kaminari-activerecord 1.0.0 → 1.2.1

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
- SHA1:
3
- metadata.gz: 711c45636af3a883dd3423099b806119be97de69
4
- data.tar.gz: c6e2277873dc10069fd8e25f7f7aae3fab3264bc
2
+ SHA256:
3
+ metadata.gz: 6876071aa2d14ad868c0b30fe2d47478c6237c8d2e32f5e09ff2d6406d308f8c
4
+ data.tar.gz: 9ab1589acaec71a5ad35eeb9f80b38d7d6abcfd4f9ee83a468ab9686e8bcb2e1
5
5
  SHA512:
6
- metadata.gz: fc118f1c18bf2f7d721e13d84451ce9b06e669a64c22aecec81251208f06ff34d58a7b2e17cd1223b44de3daafeb7e179670bf474d616778414bbf953753afdf
7
- data.tar.gz: 5e0974d4ac02e0d9e37be7b6c0e61121e14811862c9e5b7ed6b403359aa607d81796a1a59f303be4c8cce120b9b519c8c6d24b7b7746795917226c70a19d2508
6
+ metadata.gz: dc82c0b5e7aa6292bdbe94474b1a7c532706a6d07886a7a44134e49d593102d21a052a29cbd8edf187b7b1a0e736a1638bdd92fcfa7fe3bc4a6b54b2fb73599f
7
+ data.tar.gz: 7c6904976fdc124170c8b01294dacca2433e86895f60f7a1cabfccfd780cfac2f59263cd1777dc70cbf74e745939174b5ee29eee7df20909eca537b45172e001
@@ -0,0 +1 @@
1
+ See https://github.com/kaminari/kaminari/tree/master/CHANGELOG.md for changes.
data/README.md CHANGED
@@ -20,11 +20,11 @@ This gem is basically an internal gem that will be automatically bundled from ka
20
20
 
21
21
  Or if you're using ORMs other than Active Record, you might need to explicitly bundle this gem.
22
22
 
23
- See [Kaminari README (Other Framework/Library Support)](https://github.com/amatsuda/kaminari/blob/master/README.md#other-frameworklibrary-support) for details.
23
+ See [Kaminari README (Other Framework/Library Support)](https://github.com/kaminari/kaminari/blob/master/README.md#other-frameworklibrary-support) for details.
24
24
 
25
25
  ## Contributing
26
26
 
27
- Pull requests are welcome on GitHub at https://github.com/amatsuda/kaminari.
27
+ Pull requests are welcome on GitHub at https://github.com/kaminari/kaminari.
28
28
 
29
29
 
30
30
  ## License
@@ -1,5 +1,5 @@
1
- # coding: utf-8
2
1
  # frozen_string_literal: true
2
+
3
3
  lib = File.expand_path('../lib', __FILE__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
  require 'kaminari/activerecord/version'
@@ -12,8 +12,9 @@ Gem::Specification.new do |spec|
12
12
 
13
13
  spec.summary = 'Kaminari Active Record adapter'
14
14
  spec.description = 'kaminari-activerecord lets your Active Record models be paginatable'
15
- spec.homepage = 'https://github.com/amatsuda/kaminari'
15
+ spec.homepage = 'https://github.com/kaminari/kaminari'
16
16
  spec.license = "MIT"
17
+ spec.required_ruby_version = '>= 2.0.0'
17
18
 
18
19
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
20
  spec.require_paths = ["lib"]
@@ -1,8 +1,10 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "kaminari/activerecord/version"
3
4
  require 'active_support/lazy_load_hooks'
4
5
 
5
6
  ActiveSupport.on_load :active_record do
7
+ require 'kaminari/core'
6
8
  require 'kaminari/activerecord/active_record_extension'
7
9
  ::ActiveRecord::Base.send :include, Kaminari::ActiveRecordExtension
8
10
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'kaminari/activerecord/active_record_model_extension'
3
4
 
4
5
  module Kaminari
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'kaminari/activerecord/active_record_relation_methods'
3
4
 
4
5
  module Kaminari
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Kaminari
3
4
  # Active Record specific page scope methods implementations
4
5
  module ActiveRecordRelationMethods
@@ -21,21 +22,25 @@ module Kaminari
21
22
  # Total count has to be 0 if loaded records are 0
22
23
  return @total_count = 0 if (current_page == 1) && @records.empty?
23
24
  # Total count is calculable at the last page
24
- per_page = (defined?(@_per) && @_per) || default_per_page
25
- return @total_count = (current_page - 1) * per_page + @records.length if @records.any? && (@records.length < per_page)
25
+ return @total_count = (current_page - 1) * limit_value + @records.length if @records.any? && (@records.length < limit_value)
26
26
  end
27
27
 
28
28
  # #count overrides the #select which could include generated columns referenced in #order, so skip #order here, where it's irrelevant to the result anyway
29
29
  c = except(:offset, :limit, :order)
30
30
  # Remove includes only if they are irrelevant
31
31
  c = c.except(:includes) unless references_eager_loaded_tables?
32
+
33
+ c = c.limit(max_pages * limit_value) if max_pages && max_pages.respond_to?(:*)
34
+
32
35
  # .group returns an OrderedHash that responds to #count
33
36
  c = c.count(column_name)
34
37
  @total_count = if c.is_a?(Hash) || c.is_a?(ActiveSupport::OrderedHash)
35
- c.count
36
- else
37
- c.respond_to?(:count) ? c.count(column_name) : c
38
- end
38
+ c.count
39
+ elsif c.respond_to? :count
40
+ c.count(column_name)
41
+ else
42
+ c
43
+ end
39
44
  end
40
45
 
41
46
  # Turn this Relation to a "without count mode" Relation.
@@ -48,6 +53,35 @@ module Kaminari
48
53
  end
49
54
 
50
55
  # A module that makes AR::Relation paginatable without having to cast another SELECT COUNT query
56
+ module PaginatableWithoutCount
57
+ module LimitValueSetter
58
+ # refine PaginatableWithoutCount do # NOTE: this doesn't work in Ruby < 2.4
59
+ refine ::ActiveRecord::Relation do
60
+ private
61
+
62
+ # Update multiple instance variables that holds `limit` to a given value
63
+ def set_limit_value(new_limit)
64
+ @values[:limit] = new_limit
65
+
66
+ if @arel
67
+ case @arel.limit
68
+ when Integer
69
+ @arel.limit = new_limit
70
+ when Arel::Nodes::BindParam
71
+ if @arel.limit.respond_to?(:value)
72
+ @arel.limit = Arel::Nodes::BindParam.new(@arel.limit.value.with_cast_value(new_limit))
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
81
+ # NOTE: ending all modules and reopening again because using has to be called from the toplevel in Ruby 2.0
82
+ using Kaminari::PaginatableWithoutCount::LimitValueSetter
83
+
84
+ module Kaminari
51
85
  module PaginatableWithoutCount
52
86
  # Overwrite AR::Relation#load to actually load one more record to judge if the page has next page
53
87
  # then store the result in @_has_next ivar
@@ -55,13 +89,9 @@ module Kaminari
55
89
  if loaded? || limit_value.nil?
56
90
  super
57
91
  else
58
- @values[:limit] = limit_value + 1
59
- # FIXME: this could be removed when we're dropping AR 4 support
60
- @arel.limit = @values[:limit] if @arel && (Integer === @arel.limit)
92
+ set_limit_value limit_value + 1
61
93
  super
62
- @values[:limit] = limit_value - 1
63
- # FIXME: this could be removed when we're dropping AR 4 support
64
- @arel.limit = @values[:limit] if @arel && (Integer === @arel.limit)
94
+ set_limit_value limit_value - 1
65
95
 
66
96
  if @records.any?
67
97
  @records = @records.dup if (frozen = @records.frozen?)
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Kaminari
3
4
  module Activerecord
4
- VERSION = '1.0.0'
5
+ VERSION = '1.2.1'
5
6
  end
6
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kaminari-activerecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akira Matsuda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-10 00:00:00.000000000 Z
11
+ date: 2020-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kaminari-core
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 1.0.0
19
+ version: 1.2.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 1.0.0
26
+ version: 1.2.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activerecord
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -73,6 +73,7 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
+ - CHANGELOG.md
76
77
  - MIT-LICENSE
77
78
  - README.md
78
79
  - kaminari-activerecord.gemspec
@@ -81,7 +82,7 @@ files:
81
82
  - lib/kaminari/activerecord/active_record_model_extension.rb
82
83
  - lib/kaminari/activerecord/active_record_relation_methods.rb
83
84
  - lib/kaminari/activerecord/version.rb
84
- homepage: https://github.com/amatsuda/kaminari
85
+ homepage: https://github.com/kaminari/kaminari
85
86
  licenses:
86
87
  - MIT
87
88
  metadata: {}
@@ -93,15 +94,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
93
94
  requirements:
94
95
  - - ">="
95
96
  - !ruby/object:Gem::Version
96
- version: '0'
97
+ version: 2.0.0
97
98
  required_rubygems_version: !ruby/object:Gem::Requirement
98
99
  requirements:
99
100
  - - ">="
100
101
  - !ruby/object:Gem::Version
101
102
  version: '0'
102
103
  requirements: []
103
- rubyforge_project:
104
- rubygems_version: 2.6.8
104
+ rubygems_version: 3.2.0.pre1
105
105
  signing_key:
106
106
  specification_version: 4
107
107
  summary: Kaminari Active Record adapter