kasket 4.10.4 → 4.11.0

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
  SHA256:
3
- metadata.gz: a786cf4a5580eadc1ad695d662795a160dde563176371c9c0176542eadc1da6c
4
- data.tar.gz: b9261e224b6aaec4327931a5d723b3fb872cca314a6a5b68681c61b357945fdc
3
+ metadata.gz: 724d92677bcdc757b647c3238bd34e53ea21bfc17887c59186cf4431c584eda3
4
+ data.tar.gz: 38ff26970191ff1926d1e3d50e026d2d503398ef2b1bb884943b36e4e6bc4d37
5
5
  SHA512:
6
- metadata.gz: daea000b865281f12ae6fd70752f4d1418dadb00a3747452f7db9aa52230c071b8d87b23a37cd0b43a0d3a6db292c418293d25d3b97872f7a597b49b5bb81e5a
7
- data.tar.gz: f3625ddb2690f619d1f93aa2bcfdff5c72dd3b0f6debe2f19646ef6fba030d206ccab0e920fed37d0869eb8532cb1cc44adbc0d7955cfe215e938327465817ea
6
+ metadata.gz: 6d32c14b1c040d6bca217235bb7c98c2f9a042a33a38b57ee3bc0acf4ac0695eb4b1d05039df354aef624f445a09fe93ef93fb0d29a3edfcf312c5ba957404be
7
+ data.tar.gz: 506931cd595e66cccd2a6feeddeb2ff41dde52aba0fac6f5bd9e99f53b242eb5ef2626e1ff5f31c3d388594c4628e0d75fb86e7c76892e77625d441f19a393d7
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Kasket
2
2
 
3
3
  ### Puts a cap on your queries
4
- A caching layer for ActiveRecord (3.x and 4.x)
4
+ A caching layer for ActiveRecord.
5
5
 
6
6
  Developed and used by [Zendesk](http://zendesk.com).
7
7
 
@@ -101,12 +101,8 @@ module Kasket
101
101
  def kasket_quoted_value_for_column(value, column)
102
102
  if column
103
103
  conn = connection
104
- casted_value =
105
- case ActiveRecord::VERSION::MAJOR
106
- when 3 then column.type_cast(value)
107
- when 4 then column.type_cast_for_database(value)
108
- else conn.type_cast_from_column(column, value)
109
- end
104
+ type = conn.lookup_cast_type_from_column(column)
105
+ casted_value = conn.type_cast(type.serialize(value))
110
106
  conn.quote(casted_value).downcase
111
107
  else
112
108
  value.to_s
@@ -14,14 +14,10 @@ module Kasket
14
14
 
15
15
  if use_kasket?
16
16
  query = if sql.respond_to?(:to_kasket_query)
17
- if ActiveRecord::VERSION::MAJOR < 5
18
- sql.to_kasket_query(self, args[1])
17
+ if ActiveRecord::VERSION::STRING < '5.2'
18
+ sql.to_kasket_query(self, args[1].map(&:value_for_database))
19
19
  else
20
- if ActiveRecord::VERSION::STRING < '5.2'
21
- sql.to_kasket_query(self, args[1].map(&:value_for_database))
22
- else
23
- sql.to_kasket_query(self)
24
- end
20
+ sql.to_kasket_query(self)
25
21
  end
26
22
  else
27
23
  kasket_parser.parse(sanitize_sql(sql))
@@ -1,12 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
  module Kasket
3
3
  module RelationMixin
4
- # binds can be removed when support for Rails < 5 is removed
5
- def to_kasket_query(binds = nil)
4
+ def to_kasket_query
6
5
  if arel.is_a?(Arel::SelectManager)
7
- if ActiveRecord::VERSION::MAJOR < 5
8
- arel.to_kasket_query(klass, (binds || bind_values))
9
- elsif ActiveRecord::VERSION::STRING < '5.2'
6
+ if ActiveRecord::VERSION::STRING < '5.2'
10
7
  arel.to_kasket_query(klass, (@values[:where].to_h.values + Array(@values[:limit])))
11
8
  else
12
9
  arel.to_kasket_query(klass)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module Kasket
3
- VERSION = '4.10.4'
3
+ VERSION = '4.11.0'
4
4
  class Version
5
5
  MAJOR = Kasket::VERSION.split('.')[0]
6
6
  MINOR = Kasket::VERSION.split('.')[1]
@@ -49,7 +49,7 @@ module Kasket
49
49
 
50
50
  def visit_Arel_Nodes_SelectCore(node, *_)
51
51
  return :unsupported if node.groups.any?
52
- return :unsupported if ActiveRecord::VERSION::MAJOR < 5 ? node.having : node.havings.present?
52
+ return :unsupported if node.havings.present?
53
53
  return :unsupported if node.set_quantifier
54
54
  return :unsupported if !node.source || node.source.empty?
55
55
  return :unsupported if node.projections.empty?
@@ -65,6 +65,14 @@ module Kasket
65
65
  return unless (column_names - projection_names).empty?
66
66
  end
67
67
 
68
+ # un-optimize AR 6.1 by adding a redundant And node to hit visitor below
69
+ if ActiveRecord::VERSION::STRING.start_with? "6.1"
70
+ if node.wheres.size == 1
71
+ n = node.wheres[0]
72
+ node.wheres[0] = Arel::Nodes::And.new([n]) unless n.is_a?(Arel::Nodes::And)
73
+ end
74
+ end
75
+
68
76
  parts = [visit(node.source)]
69
77
 
70
78
  parts += node.wheres.map {|where| visit(where) }
@@ -73,11 +81,7 @@ module Kasket
73
81
  end
74
82
 
75
83
  def visit_Arel_Nodes_Limit(node, *_)
76
- if ActiveRecord::VERSION::MAJOR < 5
77
- { limit: node.value.to_i }
78
- else
79
- { limit: visit(node.value).to_i }
80
- end
84
+ { limit: visit(node.value).to_i }
81
85
  end
82
86
 
83
87
  def visit_Arel_Nodes_JoinSource(node, *_)
@@ -106,6 +110,8 @@ module Kasket
106
110
  [left, visit(node.right)]
107
111
  end
108
112
 
113
+ alias_method :visit_Arel_Nodes_HomogeneousIn, :visit_Arel_Nodes_In
114
+
109
115
  def visit_Arel_Nodes_Equality(node, *_)
110
116
  right =
111
117
  case node.right
@@ -134,14 +140,10 @@ module Kasket
134
140
  end
135
141
 
136
142
  def visit_Arel_Nodes_BindParam(node, *_)
137
- if ActiveRecord::VERSION::MAJOR < 5
138
- visit(@binds.shift[1])
143
+ if ActiveRecord::VERSION::STRING < '5.2'
144
+ visit(@binds.shift)
139
145
  else
140
- if ActiveRecord::VERSION::STRING < '5.2'
141
- visit(@binds.shift)
142
- else
143
- visit(node.value.value) unless node.value.value.nil?
144
- end
146
+ visit(node.value.value) unless node.value.value.nil?
145
147
  end
146
148
  end
147
149
 
@@ -157,6 +159,15 @@ module Kasket
157
159
  else quoted(node.val)
158
160
  end
159
161
  end
162
+ else # R52: val -> value
163
+ def visit_Arel_Nodes_Casted(node, *_)
164
+ v = node.value
165
+ case v
166
+ when nil then nil
167
+ when String then v
168
+ else quoted(v)
169
+ end
170
+ end
160
171
  end
161
172
 
162
173
  def visit_TrueClass(_node)
@@ -41,11 +41,7 @@ module Kasket
41
41
  attribute_sets = [attributes]
42
42
 
43
43
  previous_changes = options[:previous_changes]
44
- previous_changes ||= if respond_to?(:saved_changes)
45
- saved_changes.transform_values(&:first)
46
- else
47
- previous_changes() # keep parens or rename the local var
48
- end
44
+ previous_changes ||= saved_changes.transform_values(&:first)
49
45
  if previous_changes.present?
50
46
  old_attributes = previous_changes.each_with_object({}) do |(attribute, (old, _)), all|
51
47
  all[attribute.to_s] = old
@@ -93,23 +89,14 @@ module Kasket
93
89
  super
94
90
  end
95
91
 
96
- if ActiveRecord::VERSION::MAJOR == 3
97
- def update_column(column, value)
98
- previous_changes = { column => [attributes[column.to_s], value] }
99
- result = super
100
- clear_kasket_indices(previous_changes: previous_changes)
101
- result
102
- end
103
- else
104
- def update_columns(new_attributes)
105
- previous_attributes = attributes
106
- previous_changes = new_attributes.each_with_object({}) do |(k, v), all|
107
- all[k] = [previous_attributes[k.to_s], v]
108
- end
109
- result = super
110
- clear_kasket_indices(previous_changes: previous_changes)
111
- result
92
+ def update_columns(new_attributes)
93
+ previous_attributes = attributes
94
+ previous_changes = new_attributes.each_with_object({}) do |(k, v), all|
95
+ all[k] = [previous_attributes[k.to_s], v]
112
96
  end
97
+ result = super
98
+ clear_kasket_indices(previous_changes: previous_changes)
99
+ result
113
100
  end
114
101
 
115
102
  def kasket_after_commit_dummy
@@ -148,10 +135,6 @@ module Kasket
148
135
  model_class.after_destroy :kasket_after_destroy
149
136
  model_class.after_commit :kasket_after_commit_dummy
150
137
 
151
- if ActiveRecord::VERSION::MAJOR == 3 || (ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR == 0)
152
- model_class.after_touch :kasket_after_commit
153
- end
154
-
155
138
  class << model_class
156
139
  alias_method :transaction_without_kasket_disabled, :transaction
157
140
  alias_method :transaction, :transaction_with_kasket_disabled
data/lib/kasket.rb CHANGED
@@ -31,11 +31,8 @@ module Kasket
31
31
  CONFIGURATION[:default_expires_in] = options[:default_expires_in] if options[:default_expires_in]
32
32
 
33
33
  ActiveRecord::Base.extend(Kasket::ConfigurationMixin)
34
-
35
- if defined?(ActiveRecord::Relation)
36
- ActiveRecord::Relation.include Kasket::RelationMixin
37
- Arel::SelectManager.include Kasket::SelectManagerMixin
38
- end
34
+ ActiveRecord::Relation.include(Kasket::RelationMixin)
35
+ Arel::SelectManager.include(Kasket::SelectManagerMixin)
39
36
  end
40
37
 
41
38
  def self.cache_store=(options)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kasket
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.10.4
4
+ version: 4.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mick Staugaard
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-09-02 00:00:00.000000000 Z
12
+ date: 2023-01-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -17,20 +17,20 @@ dependencies:
17
17
  requirements:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: '4.2'
20
+ version: '5.1'
21
21
  - - "<"
22
22
  - !ruby/object:Gem::Version
23
- version: '6.1'
23
+ version: '7'
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
27
27
  requirements:
28
28
  - - ">="
29
29
  - !ruby/object:Gem::Version
30
- version: '4.2'
30
+ version: '5.1'
31
31
  - - "<"
32
32
  - !ruby/object:Gem::Version
33
- version: '6.1'
33
+ version: '7'
34
34
  description: puts a cap on your queries
35
35
  email:
36
36
  - mick@zendesk.com
@@ -61,7 +61,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
61
61
  requirements:
62
62
  - - ">="
63
63
  - !ruby/object:Gem::Version
64
- version: 2.5.0
64
+ version: 2.6.0
65
65
  required_rubygems_version: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - ">="