folio-pagination 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 94206add54cee4c16494e9d8e4df1ffca4ec071f
4
- data.tar.gz: f403b5c0289400f39f001c2a53b75482dd5bffa6
3
+ metadata.gz: 832b40bbfc520a630238027b81a611c1a503a6bf
4
+ data.tar.gz: 5f3b9010512ece27b16eb4542824216388cbbdaa
5
5
  SHA512:
6
- metadata.gz: 2e97cf79296562e8887f54734d1e717a912772ccaa508bff551ac10aff5d593273b67cc5f030ea0f45305591c836109e1f3e78373c4ce5d9c77b55a1fafd9788
7
- data.tar.gz: 8e7d031be30734a29a46ffd86aab32e7c66e2730e133f5ca990e4bc6ca2c9ef9ea3f7a0fc8966ae4fd4c9101fb81be781ee6ff55bd8cdf3070a1ff4da283320c
6
+ metadata.gz: d86e58bd0076d1754ff9ca084a411445634607997d2af0027099730dd437213df7c5a44e8b20b4094a2c3a1d49cd265a52b3b97c37855fdf5dded0f538636fbd
7
+ data.tar.gz: 62197be67cf3966aa7ccf28830fcccf47570bbea7525b5dbc22ae15c147917bb76ce83acb0847137b277d85c35a4a8deb4e95ec26fc442065664d12c74ace5bd
@@ -49,7 +49,18 @@ module Folio
49
49
  current_page = page.first_page if current_page.nil?
50
50
  page.current_page = current_page
51
51
  page.per_page = options[:per_page] || self.per_page
52
- page.total_entries = options.fetch(:total_entries) { self.respond_to?(:count) ? self.count : nil }
52
+
53
+ page.total_entries = options.fetch(:total_entries) do
54
+ if self.respond_to?(:count)
55
+ if self.is_a?(::ActiveRecord::Relation) && ::Rails.version >= '4'
56
+ self.count(:all)
57
+ else
58
+ self.count
59
+ end
60
+ else
61
+ nil
62
+ end
63
+ end
53
64
  page
54
65
  end
55
66
 
@@ -1,3 +1,3 @@
1
1
  module Folio
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
@@ -116,19 +116,28 @@ module Folio
116
116
 
117
117
  def paginate(options={})
118
118
  if !options.has_key?(:total_entries)
119
- group_values = self.scoped.group_values
119
+ scope = if ::Rails.version < '4'
120
+ self.scoped
121
+ elsif self.is_a?(::ActiveRecord::Relation)
122
+ self
123
+ elsif self.is_a?(::ActiveRecord::Base)
124
+ self.all
125
+ else
126
+ self.scope
127
+ end
128
+ group_values = scope.group_values
120
129
  unless group_values.empty?
121
130
  # total_entries left to an auto-count, but the relation being
122
131
  # paginated has a grouping. we need to do a special count, lest
123
132
  # self.count give us a hash instead of the integer we expect.
124
- if self.scoped.having_values.empty?
125
- options[:total_entries] = except(:group).select(group_values).uniq.count
133
+ if scope.having_values.empty? && group_values.length == 1 # multi-column distinct counts are broken right now (as of rails 4.2.5) :(
134
+ options[:total_entries] = except(:group, :select).select(group_values).uniq.count
126
135
  else
127
136
  options[:total_entries] = unscoped.from("(#{to_sql}) a").count
128
137
  end
129
138
  end
130
139
  end
131
- super(options).all
140
+ super(options).to_a
132
141
  end
133
142
  end
134
143
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: folio-pagination
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jacob Fugal
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-02 00:00:00.000000000 Z
11
+ date: 2016-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  version: '0'
118
118
  requirements: []
119
119
  rubyforge_project:
120
- rubygems_version: 2.4.6
120
+ rubygems_version: 2.4.7
121
121
  signing_key:
122
122
  specification_version: 4
123
123
  summary: Folio is a library for pagination. It's meant to be nearly compatible with