kaminari-activerecord 1.1.0 → 1.2.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ea8e3ace660d361f867d8358b4b8da5330fe38cf58e67a5f51ea52ba8c86d103
4
- data.tar.gz: bfab69ff0b3736bae5e657ccd3bdeb9188dc689205cb56c7d9eb9ab7c782c499
3
+ metadata.gz: e02b1d73471d5966fc0a51c928644d0f47318e6de292267cecfc6742983c24dc
4
+ data.tar.gz: 77dfa6a9124df355c7b3ac038f5c8db374ee0769f58d22ebb9db48b448fe5b00
5
5
  SHA512:
6
- metadata.gz: 7a53c8910b98e6dbe3e62d8e5ca32869c0d591a3b54394422cab727df6bbd7193e836201e6de2dc9a18724f5de7f3c88f7ad314b5a39d94a4a21d154f61fb065
7
- data.tar.gz: 81d0a8aff3e2cf06b0014b8460d1070ed30d0b0f7b735827a79a179d07590c94ae24772ee07aa3ace8ae71e9b5808d95b0432b6db92f9109cc3ab8dc53f37b94
6
+ metadata.gz: f5cc9d8c8ee50631d2086ac46b50f9b4acd2cb7860a750089de6665578465d1130f0dbcae116c904d8646dc4daae36ffe87d9a71aadcfb8171d76267802fae99
7
+ data.tar.gz: 6ec4e5f73926f62ae1a8ce0ccca455932336147cef42203be1ffd821199317fed96f87a76ec8d3277b2a2e1c5c4cb48dc0b7f5e8703d273b03d269d0de59f8e1
@@ -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'
@@ -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,23 +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
- elsif c.respond_to? :count
37
- c.count(column_name)
38
- else
39
- c
40
- end
38
+ c.count
39
+ elsif c.respond_to? :count
40
+ c.count(column_name)
41
+ else
42
+ c
43
+ end
41
44
  end
42
45
 
43
46
  # Turn this Relation to a "without count mode" Relation.
@@ -50,6 +53,37 @@ module Kaminari
50
53
  end
51
54
 
52
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 hold `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.class.name
68
+ when 'Integer', 'Fixnum'
69
+ @arel.limit = new_limit
70
+ when 'ActiveModel::Attribute::WithCastValue' # comparing by class name because ActiveModel::Attribute::WithCastValue is a private constant
71
+ @arel.limit = build_cast_value 'LIMIT', new_limit
72
+ when 'Arel::Nodes::BindParam'
73
+ if @arel.limit.respond_to?(:value)
74
+ @arel.limit = Arel::Nodes::BindParam.new(@arel.limit.value.with_cast_value(new_limit))
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
83
+ # NOTE: ending all modules and reopening again because using has to be called from the toplevel in Ruby 2.0
84
+ using Kaminari::PaginatableWithoutCount::LimitValueSetter
85
+
86
+ module Kaminari
53
87
  module PaginatableWithoutCount
54
88
  # Overwrite AR::Relation#load to actually load one more record to judge if the page has next page
55
89
  # then store the result in @_has_next ivar
@@ -57,13 +91,9 @@ module Kaminari
57
91
  if loaded? || limit_value.nil?
58
92
  super
59
93
  else
60
- @values[:limit] = limit_value + 1
61
- # FIXME: this could be removed when we're dropping AR 4 support
62
- @arel.limit = @values[:limit] if @arel && (Integer === @arel.limit)
94
+ set_limit_value limit_value + 1
63
95
  super
64
- @values[:limit] = limit_value - 1
65
- # FIXME: this could be removed when we're dropping AR 4 support
66
- @arel.limit = @values[:limit] if @arel && (Integer === @arel.limit)
96
+ set_limit_value limit_value - 1
67
97
 
68
98
  if @records.any?
69
99
  @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.1.0'
5
+ VERSION = '1.2.2'
5
6
  end
6
7
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "kaminari/activerecord/version"
3
4
  require 'active_support/lazy_load_hooks'
4
5
 
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.1.0
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akira Matsuda
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-13 00:00:00.000000000 Z
11
+ date: 2021-12-25 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.1.0
19
+ version: 1.2.2
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.1.0
26
+ version: 1.2.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activerecord
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -86,7 +86,7 @@ homepage: https://github.com/kaminari/kaminari
86
86
  licenses:
87
87
  - MIT
88
88
  metadata: {}
89
- post_install_message:
89
+ post_install_message:
90
90
  rdoc_options: []
91
91
  require_paths:
92
92
  - lib
@@ -101,9 +101,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
101
  - !ruby/object:Gem::Version
102
102
  version: '0'
103
103
  requirements: []
104
- rubyforge_project:
105
- rubygems_version: 2.6.14
106
- signing_key:
104
+ rubygems_version: 3.3.0.dev
105
+ signing_key:
107
106
  specification_version: 4
108
107
  summary: Kaminari Active Record adapter
109
108
  test_files: []