kasket 3.2.0 → 4.0.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
2
  SHA1:
3
- metadata.gz: 8fd8b1112932a3d14ed1e43ab61ad826ba02c5f0
4
- data.tar.gz: 997f6891f0df65c1299a3d0da4f1e990a0c6a0fc
3
+ metadata.gz: e2a4548deae3c98ad894dbd54829ca55c5fcd0fa
4
+ data.tar.gz: 3f746fed7e8508b8d169974c9e660d35f1be92d2
5
5
  SHA512:
6
- metadata.gz: 9eb57e261693839d9b4d81060fadf64737f528c8d37adcc3d3f98459e2947832dbcc3ac96379c2775cde2486731ccf5f1a3178a9ac49e376f93574154a1f7b90
7
- data.tar.gz: 19c1289828483003fb8a979969aee6198ac4cbdbe47452b82cbbaa15dee26280c31f7a91559994afa4b856f960fce4411daa1ba9297bac265d6092f347173d32
6
+ metadata.gz: eb3b6225c51e1f02c72d9fe1af8c093ee5c6ae512ad127beae372e016b5ab08072db0020ad9059e0c1c46cb1362b12a36d78eb07da1af460e2a3e7d6e5bab291
7
+ data.tar.gz: d3f7df44370ca505b8c686d9a7d00534c7e6b8dd8e5d08ab30fd64080949486827239084915916d04c428cbeef01235c2189041cb450cd0756506b54bdb341ba
@@ -36,12 +36,7 @@ module Kasket
36
36
  key = attribute_value_pairs.map do |attribute, value|
37
37
  column = columns_hash[attribute.to_s]
38
38
  value = nil if value.blank?
39
- quoted_value = if column
40
- connection.quote(column.type_cast(value), column).downcase
41
- else
42
- value.to_s
43
- end
44
- attribute.to_s << '=' << quoted_value
39
+ attribute.to_s << '=' << quoted_value_for_column(value, column)
45
40
  end.join('/')
46
41
 
47
42
  if key.size > (250 - kasket_key_prefix.size) || key =~ /\s/
@@ -83,5 +78,19 @@ module Kasket
83
78
  extend DirtyMixin unless respond_to?(:kasket_dirty_methods)
84
79
  extend ReadMixin unless methods.map(&:to_sym).include?(:find_by_sql_with_kasket)
85
80
  end
81
+
82
+ private
83
+ def quoted_value_for_column(value, column)
84
+ if column
85
+ casted_value = if column.respond_to?(:type_cast_for_database)
86
+ column.type_cast_for_database(value) # Rails 4.2 and up
87
+ else
88
+ column.type_cast(value)
89
+ end
90
+ connection.quote(casted_value).downcase
91
+ else
92
+ value.to_s
93
+ end
94
+ end
86
95
  end
87
96
  end
@@ -10,14 +10,14 @@ module Kasket
10
10
 
11
11
  def initialize(model_class)
12
12
  @model_class = model_class
13
- @supported_query_pattern = /^select \* from (?:`|")#{@model_class.table_name}(?:`|") where \((.*)\)(|\s+limit 1)\s*$/i
13
+ @supported_query_pattern = /^select\s+((?:`|")#{@model_class.table_name}(?:`|")\.)?\* from (?:`|")#{@model_class.table_name}(?:`|") where (.*?)(|\s+limit 1)\s*$/i
14
14
  @table_and_column_pattern = /(?:(?:`|")?#{@model_class.table_name}(?:`|")?\.)?(?:`|")?([a-zA-Z]\w*)(?:`|")?/ # Matches: `users`.id, `users`.`id`, users.id, id
15
15
  @key_eq_value_pattern = /^[\(\s]*#{@table_and_column_pattern}\s+(=|IN)\s+#{VALUE}[\)\s]*$/ # Matches: KEY = VALUE, (KEY = VALUE), ()(KEY = VALUE))
16
16
  end
17
17
 
18
18
  def parse(sql)
19
19
  if match = @supported_query_pattern.match(sql)
20
- where, limit = match[1], match[2]
20
+ where, limit = match[2], match[3]
21
21
 
22
22
  query = Hash.new
23
23
  query[:attributes] = sorted_attribute_value_pairs(where)
@@ -1,9 +1,11 @@
1
1
  module Kasket
2
2
  module RelationMixin
3
- def to_kasket_query(binds = [])
3
+ def to_kasket_query(binds = nil)
4
4
  if arel.is_a?(Arel::SelectManager)
5
- arel.to_kasket_query(klass, binds)
5
+ arel.to_kasket_query(klass, (binds || bind_values))
6
6
  end
7
+ rescue TypeError # unsupported object in ast
8
+ return nil
7
9
  end
8
10
  end
9
11
  end
@@ -1,8 +1,8 @@
1
1
  module Kasket
2
2
  class Version
3
- MAJOR = 3
4
- MINOR = 2
5
- PATCH = 0
3
+ MAJOR = 4
4
+ MINOR = 0
5
+ PATCH = 1
6
6
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
  PROTOCOL = 4
8
8
  end
@@ -5,6 +5,7 @@ module Kasket
5
5
  def initialize(model_class, binds)
6
6
  @model_class = model_class
7
7
  @binds = binds.dup
8
+ super()
8
9
  end
9
10
 
10
11
  def accept(node)
@@ -107,13 +108,16 @@ module Kasket
107
108
  end
108
109
  end
109
110
 
110
- # only gets used on 1.8.7
111
111
  def visit_Arel_Nodes_BindParam(x, *_)
112
- @binds.shift[1]
112
+ visit(@binds.shift[1])
113
113
  end
114
114
 
115
115
  def visit_Array(node, *_)
116
- node.map {|value| quoted(value) }
116
+ node.map {|value| visit(value) }
117
+ end
118
+
119
+ def visit_Arel_Nodes_Casted(node, *_)
120
+ quoted(node.val)
117
121
  end
118
122
 
119
123
  #TODO: We are actually not using this?
@@ -31,7 +31,7 @@ module Kasket
31
31
 
32
32
  def store_in_kasket
33
33
  if kasket_cacheable? && kasket_key
34
- Kasket.cache.write(kasket_key, @attributes.dup)
34
+ Kasket.cache.write(kasket_key, @attributes.to_h.dup)
35
35
  end
36
36
  end
37
37
 
@@ -77,6 +77,7 @@ module Kasket
77
77
  end
78
78
 
79
79
  model_class.after_save :clear_kasket_indices
80
+ model_class.after_touch :clear_kasket_indices
80
81
  model_class.after_destroy :clear_kasket_indices
81
82
 
82
83
  model_class.alias_method_chain :reload, :kasket_clearing
@@ -89,4 +90,3 @@ module Kasket
89
90
  end
90
91
  end
91
92
  end
92
-
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: 3.2.0
4
+ version: 4.0.1
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: 2014-05-30 00:00:00.000000000 Z
12
+ date: 2015-08-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -20,7 +20,7 @@ dependencies:
20
20
  version: '3.2'
21
21
  - - "<"
22
22
  - !ruby/object:Gem::Version
23
- version: '4.2'
23
+ version: '4.3'
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
@@ -30,7 +30,7 @@ dependencies:
30
30
  version: '3.2'
31
31
  - - "<"
32
32
  - !ruby/object:Gem::Version
33
- version: '4.2'
33
+ version: '4.3'
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: rake
36
36
  requirement: !ruby/object:Gem::Requirement
@@ -60,21 +60,21 @@ dependencies:
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  - !ruby/object:Gem::Dependency
63
- name: appraisal
63
+ name: mocha
64
64
  requirement: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: 0.5.0
68
+ version: '0'
69
69
  type: :development
70
70
  prerelease: false
71
71
  version_requirements: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: 0.5.0
75
+ version: '0'
76
76
  - !ruby/object:Gem::Dependency
77
- name: mocha
77
+ name: wwtd
78
78
  requirement: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - ">="
@@ -88,7 +88,7 @@ dependencies:
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  - !ruby/object:Gem::Dependency
91
- name: wwtd
91
+ name: bump
92
92
  requirement: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - ">="