arel-extensions 6.0.0.1 → 6.0.0.4

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: d95a12f5c8e5e48eebb56d5ab99ffc4fe80db96ee28041beede8dbfc8a8920cc
4
- data.tar.gz: 5e9c19213eb0d7c0d43e2f506c5f08acc651b3f4e33e5ec62dc53d0b79c87ced
3
+ metadata.gz: '08c6ce3898d57f105c59837161e36e1fe45f25afd4daa95d54916bef1c3782e5'
4
+ data.tar.gz: 1f2efc0c80e2b25c826421126eb8d963a7244b1c386a7a0f871b46fcad701c11
5
5
  SHA512:
6
- metadata.gz: fd222a989cb6374f50669d3a9ec6c7e5959b763e62bbdf6c8578db7bc4d3bc94281257c41d6c3927645ef6c5cdb6be3df6f786d8f81e1517772dfb880449ed66
7
- data.tar.gz: 50669ec434c338f89fe2d5318a868e74afc3fbf388929788c94a54853eb0c4364916fcce9f908e8dc494bcf46b03a6fe5773cdc58e5445effe85e509e8d00414
6
+ metadata.gz: d5610a339bd005e10ef756715bf25b0cc96dc471e6fec233a8f9735e6c4bb05f50425aaf0f465b6d4e57c0320949ed80a6e93d46b399e1975a4753185112fac3
7
+ data.tar.gz: a5fde1fd877f44e52bde43595d4eb1237742f85ea338ad1a00597d075c5d0f30320bac95b41d5b58bf1460784035d51f14728702e22dd4cc401293137b28b1fb
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
1
  .DS_Store
2
+ *.gem
data/Gemfile.lock CHANGED
@@ -1,23 +1,23 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- arel-extensions (6.0.0)
4
+ arel-extensions (6.0.0.2)
5
5
  activerecord (>= 6.0.0.rc1)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activemodel (6.0.0.rc1)
11
- activesupport (= 6.0.0.rc1)
12
- activerecord (6.0.0.rc1)
13
- activemodel (= 6.0.0.rc1)
14
- activesupport (= 6.0.0.rc1)
15
- activesupport (6.0.0.rc1)
10
+ activemodel (6.0.0.rc2)
11
+ activesupport (= 6.0.0.rc2)
12
+ activerecord (6.0.0.rc2)
13
+ activemodel (= 6.0.0.rc2)
14
+ activesupport (= 6.0.0.rc2)
15
+ activesupport (6.0.0.rc2)
16
16
  concurrent-ruby (~> 1.0, >= 1.0.2)
17
17
  i18n (>= 0.7, < 2)
18
18
  minitest (~> 5.1)
19
19
  tzinfo (~> 1.1)
20
- zeitwerk (~> 2.1, >= 2.1.4)
20
+ zeitwerk (~> 2.1, >= 2.1.8)
21
21
  ansi (1.5.0)
22
22
  builder (3.2.3)
23
23
  concurrent-ruby (1.1.5)
@@ -36,7 +36,7 @@ GEM
36
36
  thread_safe (0.3.6)
37
37
  tzinfo (1.2.5)
38
38
  thread_safe (~> 0.1)
39
- zeitwerk (2.1.6)
39
+ zeitwerk (2.1.9)
40
40
 
41
41
  PLATFORMS
42
42
  ruby
@@ -1,7 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = 'arel-extensions'
3
- gem.version = '6.0.0.1'
4
-
3
+ gem.version = '6.0.0.4'
5
4
  gem.authors = ["Jon Bracy"]
6
5
  gem.email = ["jonbracy@gmail.com"]
7
6
  gem.summary = %q{Adds support for missing SQL operators and functions to Arel}
@@ -2,7 +2,15 @@ module Arel
2
2
  module Visitors
3
3
  class Sunstone
4
4
  private
5
-
5
+
6
+ def visit_Hash o, collector
7
+ value = {}
8
+ o.each do |key, value|
9
+ value[visit(key, collector)] = visit(value, collector)
10
+ end
11
+ value
12
+ end
13
+
6
14
  def visit_Arel_Nodes_Contains o, collector
7
15
  key = visit(o.left, collector)
8
16
  value = { contains: visit(o.right, collector) }
@@ -88,7 +96,7 @@ module Arel
88
96
 
89
97
  def visit_Arel_Nodes_HasAnyKey o, collector
90
98
  key = visit(o.left, collector)
91
- value = {has_any_key: Array(o.right).map(&:to_s)}
99
+ value = { has_any_key: visit(Array(o.right), collector) }
92
100
 
93
101
  if key.is_a?(Hash)
94
102
  add_to_bottom_of_hash(key, value)
data/test/database.rb CHANGED
@@ -22,6 +22,7 @@ ActiveRecord::Migration.suppress_messages do
22
22
  create_table "properties", force: :cascade do |t|
23
23
  t.string "name", limit: 255
24
24
  t.tsvector 'vector_col'
25
+ t.jsonb 'metadata'
25
26
  end
26
27
 
27
28
  end
@@ -0,0 +1,98 @@
1
+ require 'test_helper'
2
+
3
+ class SunstoneTest < ActiveSupport::TestCase
4
+
5
+ # schema do
6
+ # create_table "properties", force: :cascade do |t|
7
+ # t.jsonb 'metadata'
8
+ # end
9
+ # end
10
+
11
+ # class Property < ActiveRecord::Base
12
+ # end
13
+
14
+ # test "::filter json_column: STRING throws an error" do
15
+ # assert_raises(ActiveRecord::UnkownFilterError) do
16
+ # Property.filter(metadata: 'string').load
17
+ # end
18
+ # end
19
+
20
+ # test "::filter json_column: {eq: JSON_HASH}" do
21
+ # query = Property.where(metadata: {eq: {json: 'string'}})
22
+ # assert_equal(<<-SQL.strip.gsub(/\s+/, ' '), query.to_sql.strip)
23
+ # SELECT "properties".*
24
+ # FROM "properties"
25
+ # WHERE "properties"."metadata" = '{\"json\":\"string\"}'
26
+ # SQL
27
+ # end
28
+
29
+ test "::filter json_column: {contains: JSON_HASH}" do
30
+ query = Property.where(Property.arel_attribute('metadata').contains({json: 'string'}))
31
+ assert_equal '', query.to_sar.path
32
+ # query = Property.where(metadata: {contains: {json: 'string'}})
33
+ # assert_equal(<<-SQL.strip.gsub(/\s+/, ' '), query.to_sql.strip)
34
+ # SELECT "properties".*
35
+ # FROM "properties"
36
+ # WHERE "properties"."metadata" @> '{\"json\":\"string\"}'
37
+ # SQL
38
+ end
39
+
40
+ # test "::filter json_column: {contained_by: JSON_HASH}" do
41
+ # query = Property.filter(metadata: {contained_by: {json: 'string'}})
42
+ # assert_equal(<<-SQL.strip.gsub(/\s+/, ' '), query.to_sql.strip)
43
+ # SELECT "properties".*
44
+ # FROM "properties"
45
+ # WHERE "properties"."metadata" <@ '{\"json\":\"string\"}'
46
+ # SQL
47
+ # end
48
+
49
+ # test "::filter json_column: {has_key: STRING}" do
50
+ # query = Property.filter(metadata: {has_key: 'string'})
51
+ # assert_equal(<<-SQL.strip.gsub(/\s+/, ' '), query.to_sql.strip)
52
+ # SELECT "properties".*
53
+ # FROM "properties"
54
+ # WHERE "properties"."metadata" ? 'string'
55
+ # SQL
56
+ # end
57
+
58
+ # test "::filter json_column.subkey: {eq: JSON_HASH}" do
59
+ # query = Property.filter("metadata.subkey" => {eq: 'string'})
60
+ # assert_equal(<<-SQL.strip.gsub(/\s+/, ' '), query.to_sql.strip)
61
+ # SELECT "properties".*
62
+ # FROM "properties"
63
+ # WHERE "properties"."metadata"#>'{subkey}' = 'string'
64
+ # SQL
65
+ # end
66
+
67
+ # test "::filter json_column: BOOLEAN" do
68
+ # query = Property.filter(metadata: true)
69
+ # assert_equal(<<-SQL.strip.gsub(/\s+/, ' '), query.to_sql.strip)
70
+ # SELECT "properties".*
71
+ # FROM "properties"
72
+ # WHERE "properties"."metadata" IS NOT NULL
73
+ # SQL
74
+
75
+ # query = Property.filter(metadata: "true")
76
+ # assert_equal(<<-SQL.strip.gsub(/\s+/, ' '), query.to_sql.strip)
77
+ # SELECT "properties".*
78
+ # FROM "properties"
79
+ # WHERE "properties"."metadata" IS NOT NULL
80
+ # SQL
81
+
82
+ # query = Property.filter(metadata: false)
83
+ # assert_equal(<<-SQL.strip.gsub(/\s+/, ' '), query.to_sql.strip)
84
+ # SELECT "properties".*
85
+ # FROM "properties"
86
+ # WHERE "properties"."metadata" IS NULL
87
+ # SQL
88
+
89
+ # query = Property.filter(metadata: "false")
90
+ # assert_equal(<<-SQL.strip.gsub(/\s+/, ' '), query.to_sql.strip)
91
+ # SELECT "properties".*
92
+ # FROM "properties"
93
+ # WHERE "properties"."metadata" IS NULL
94
+ # SQL
95
+ # end
96
+
97
+
98
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arel-extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.0.1
4
+ version: 6.0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Bracy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-26 00:00:00.000000000 Z
11
+ date: 2019-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -148,6 +148,7 @@ files:
148
148
  - lib/arel/visitors/postgresql_extensions.rb
149
149
  - lib/arel/visitors/sunstone_extensions.rb
150
150
  - test/database.rb
151
+ - test/sunstone_test.rb
151
152
  - test/test_helper.rb
152
153
  - test/ts_test.rb
153
154
  homepage: https://github.com/malomalo/arel-extensions
@@ -175,5 +176,6 @@ specification_version: 4
175
176
  summary: Adds support for missing SQL operators and functions to Arel
176
177
  test_files:
177
178
  - test/database.rb
179
+ - test/sunstone_test.rb
178
180
  - test/test_helper.rb
179
181
  - test/ts_test.rb