ahoy_matey 4.0.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
  SHA256:
3
- metadata.gz: 1fb8aecda5242614f518d06dbdc9449305f0ed30677d667e01eb1edefc627bc7
4
- data.tar.gz: 8f52fbe0bab0a0ac1c5722b06f342add3d31c0c441230b77f03ae566e07f746b
3
+ metadata.gz: cea71919e25f8f3b9ce9f3ccea43f8d11ec29d1995b3c5078428a8d4a7948457
4
+ data.tar.gz: 81316ad1b9fc956bf0ece8c23c63570d5f333e0f7c781406e1b2214e965feebb
5
5
  SHA512:
6
- metadata.gz: '059927d7fe2344882860ae81ff23e142a09ed955da818da8d3e679b03173b39e64ffc611e4e682a912901678cd9b790b461805f788c423cd2b4331c2a340c226'
7
- data.tar.gz: f2d53c35500ee4d30485cfbf6c5d444cbf03c50cec4762783a972411343e19b8baf53b61286cc4aa78bbbe98a69df21da701989422263780447341fdce756db0
6
+ metadata.gz: c52e5f32c8fd7f9d070867e8d53868a58365430ed6d7bfa3baa1dd826f042875d42fadddc7991bf5c1c0b836021dd1b2634e8c2e43fa88a055dff9b8aeae70e5
7
+ data.tar.gz: e3cdb04028a3277f678f65bf713d3a93339be369d4ed8af73a87bddd549b2ffd7983abd91443858e4411459442b8e292612381ea3ff731ce53d8f0b50f995857
data/CHANGELOG.md CHANGED
@@ -1,6 +1,12 @@
1
+ ## 4.0.1 (2021-08-18)
2
+
3
+ - Added support for `where_event`, `where_props`, and `where_group` for SQLite
4
+ - Fixed results with `where_event`
5
+ - Fixed results with `where_props` and `where_group` when used with other scopes
6
+
1
7
  ## 4.0.0 (2021-08-14)
2
8
 
3
- - Disabled geocoding by default
9
+ - Disabled geocoding by default (this was already the case for new installations with 3.2.0+)
4
10
  - Made the `geocoder` gem an optional dependency
5
11
  - Updated Ahoy.js to 0.4.0
6
12
  - Updated API to return 400 status code when missing required parameters
@@ -8,7 +8,9 @@ module Ahoy
8
8
  end
9
9
 
10
10
  def where_props(properties)
11
- relation = self
11
+ return all if properties.empty?
12
+
13
+ relation = all
12
14
  if respond_to?(:columns_hash)
13
15
  column_type = columns_hash["properties"].type
14
16
  adapter_name = connection.adapter_name.downcase
@@ -17,18 +19,9 @@ module Ahoy
17
19
  end
18
20
  case adapter_name
19
21
  when "mongoid"
20
- relation = where(Hash[properties.map { |k, v| ["properties.#{k}", v] }])
22
+ relation = where(properties.to_h { |k, v| ["properties.#{k}", v] })
21
23
  when /mysql/
22
- column = column_type == :json || connection.try(:mariadb?) ? "properties" : "CAST(properties AS JSON)"
23
- properties.each do |k, v|
24
- if v.nil?
25
- v = "null"
26
- elsif v == true
27
- v = "true"
28
- end
29
-
30
- relation = relation.where("JSON_UNQUOTE(JSON_EXTRACT(#{column}, ?)) = ?", "$.#{k}", v.as_json)
31
- end
24
+ relation = relation.where("JSON_CONTAINS(properties, ?, '$') = 1", properties.to_json)
32
25
  when /postgres|postgis/
33
26
  case column_type
34
27
  when :jsonb
@@ -45,6 +38,15 @@ module Ahoy
45
38
  else
46
39
  relation = relation.where("properties::jsonb @> ?", properties.to_json)
47
40
  end
41
+ when /sqlite/
42
+ properties.each do |k, v|
43
+ relation =
44
+ if v.nil?
45
+ relation.where("JSON_EXTRACT(properties, ?) IS NULL", "$.#{k}")
46
+ else
47
+ relation.where("JSON_EXTRACT(properties, ?) = ?", "$.#{k}", v.as_json)
48
+ end
49
+ end
48
50
  else
49
51
  raise "Adapter not supported: #{adapter_name}"
50
52
  end
@@ -56,7 +58,7 @@ module Ahoy
56
58
  # like with group
57
59
  props.flatten!
58
60
 
59
- relation = self
61
+ relation = all
60
62
  if respond_to?(:columns_hash)
61
63
  column_type = columns_hash["properties"].type
62
64
  adapter_name = connection.adapter_name.downcase
@@ -67,10 +69,9 @@ module Ahoy
67
69
  when "mongoid"
68
70
  raise "Adapter not supported: #{adapter_name}"
69
71
  when /mysql/
70
- column = column_type == :json || connection.try(:mariadb?) ? "properties" : "CAST(properties AS JSON)"
71
72
  props.each do |prop|
72
73
  quoted_prop = connection.quote("$.#{prop}")
73
- relation = relation.group("JSON_UNQUOTE(JSON_EXTRACT(#{column}, #{quoted_prop}))")
74
+ relation = relation.group("JSON_UNQUOTE(JSON_EXTRACT(properties, #{quoted_prop}))")
74
75
  end
75
76
  when /postgres|postgis/
76
77
  # convert to jsonb to fix
@@ -82,6 +83,11 @@ module Ahoy
82
83
  quoted_prop = connection.quote(prop)
83
84
  relation = relation.group("properties#{cast} -> #{quoted_prop}")
84
85
  end
86
+ when /sqlite/
87
+ props.each do |prop|
88
+ quoted_prop = connection.quote("$.#{prop}")
89
+ relation = relation.group("JSON_EXTRACT(properties, #{quoted_prop})")
90
+ end
85
91
  else
86
92
  raise "Adapter not supported: #{adapter_name}"
87
93
  end
data/lib/ahoy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ahoy
2
- VERSION = "4.0.0"
2
+ VERSION = "4.0.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ahoy_matey
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-14 00:00:00.000000000 Z
11
+ date: 2021-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport