active_resource_pagination 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.0.5
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{active_resource_pagination}
8
- s.version = "0.0.4"
8
+ s.version = "0.0.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Dorren Chen"]
@@ -5,9 +5,9 @@ module ActiveResource
5
5
  # This adds pagination support to Active Resource. For example
6
6
  #
7
7
  # Article.paginate
8
- # Article.paginate(:all, :page => 2, :per_page => 20)
9
- # Article.paginate(:all, :page => 2, :per_page => 20, :total_entries => 123)
10
- # Article.paginate(:all, :from => :most_popular,
8
+ # Article.paginate(:page => 2, :per_page => 20)
9
+ # Article.paginate(:page => 2, :per_page => 20, :total_entries => 123)
10
+ # Article.paginate(:from => :most_popular,
11
11
  # :params => {:year => 2010, :page => 1, :per_page => 20})
12
12
  #
13
13
  # To set default per_page value for all resources. you can do
@@ -31,15 +31,17 @@ module ActiveResource
31
31
  # if resource backend doesn't paginate and retursn all result, then this method automatically
32
32
  # sets the total_entry count from the result. Otherwise, you have to pass in the
33
33
  # :total_entries count value manually.
34
- def paginate(*args)
35
- options = args.last || {}
36
- options = options[:params] || options
37
- options = options.reject{|k, v| v.blank?}
38
- options = {:page => 1, :per_page => per_page}.merge(options)
39
- page = options[:page]
40
- per_page = options[:per_page]
34
+ def paginate(options={})
35
+ if options[:params]
36
+ pg_params = options[:params] = with_default_params(options[:params])
37
+ else
38
+ pg_params = options = with_default_params(options)
39
+ end
40
+
41
+ page = pg_params[:page]
42
+ per_page = pg_params[:per_page]
41
43
 
42
- arr = find(*args) || []
44
+ arr = find(:all, options) || []
43
45
  total_entries = options[:total_entries] || arr.size
44
46
  WillPaginate::Collection.create(page, per_page, total_entries) do |pager|
45
47
  if arr.size > per_page
@@ -49,6 +51,11 @@ module ActiveResource
49
51
  end
50
52
  end
51
53
  end
54
+
55
+ protected
56
+ def with_default_params(options)
57
+ {:page => 1, :per_page => per_page}.merge(options.reject{|k, v| v.blank?})
58
+ end
52
59
  end
53
60
  end
54
61
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 4
9
- version: 0.0.4
8
+ - 5
9
+ version: 0.0.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Dorren Chen