arel-extensions 1.5.2 → 1.6.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
- SHA1:
3
- metadata.gz: 0f5c8d435e6378cdaf63398e946ea88c0404589c
4
- data.tar.gz: c2db5c4c9cdc751ab836f241aa1f20232da98aef
2
+ SHA256:
3
+ metadata.gz: 52a47012efafaa4b4d73f2b13b017a3e35c75587525de84c16dd4a585a29909e
4
+ data.tar.gz: 2a8a38a06be27912f2877bebd701a4f1f1dcce1e0d69211611f660de612f902c
5
5
  SHA512:
6
- metadata.gz: 93ef06c1a1fd9f451cb3b4914c88e82a982ce923e2ba70e539d6ef2882ea9e3d042f8c9994fbbca9d225856ad0bd7933ea446ec69224515550c0fbde602fbc0f
7
- data.tar.gz: 9fd582e8334735fdd142ffbf3745010eb1c4b0f1661f1a77e0ca11acb6516fe1d8fa894f7c82886475b4dca284c09d91024ef78413df4782a11dec1f3f584f4f
6
+ metadata.gz: 1b533cb96f4274645663d55e5b2ff5784784490f72baa34925791914c95b76724b06a9f7b64873e8c5f5f85f64622b26256bff7f5cd7caa1f29c3f9906dc4d88
7
+ data.tar.gz: e9ce3d9dbb5d1efbc757e032df5809cc5aad64bdd4ee5eaaf7097ff4f437b0a16536367867e72475a4e019bf759ac81dcc7aaeedbe1e313b5d1760debc3e4856
data/.travis.yml ADDED
@@ -0,0 +1,42 @@
1
+ language: ruby
2
+ sudo: false
3
+
4
+ cache:
5
+ bundler: true
6
+
7
+ rvm:
8
+ - 2.3.4
9
+ - 2.4.1
10
+
11
+ env:
12
+ matrix:
13
+ - RAILS_VERSION=v5.1.0 GEM=ar:mysql2
14
+ - RAILS_VERSION=v5.1.0 GEM=ar:sqlite3
15
+ - RAILS_VERSION=v5.1.0 GEM=ar:postgresql
16
+ - RAILS_VERSION=v5.1.1 GEM=ar:mysql2
17
+ - RAILS_VERSION=v5.1.1 GEM=ar:sqlite3
18
+ - RAILS_VERSION=v5.1.1 GEM=ar:postgresql
19
+
20
+ addons:
21
+ postgresql: "9.4"
22
+
23
+ before_install:
24
+ - unset BUNDLE_GEMFILE
25
+ - gem update --system
26
+ - gem update bundler
27
+
28
+ install:
29
+ - git clone https://github.com/rails/rails.git ~/build/rails
30
+ - pushd ~/build/rails
31
+ - git checkout $RAILS_VERSION
32
+ - sed -i "s/Gem.ruby, '-w'/Gem.ruby, '-w0'/" ~/build/rails/activerecord/Rakefile
33
+ - sed -i "s/t.warning = true/t.warning = false/g" ~/build/rails/activerecord/Rakefile
34
+ - sed -i "/require 'support\/connection'/a \$LOAD_PATH.unshift\(File.expand_path\('~\/build\/malomalo\/arel-extensions\/lib'\)\)\nrequire 'arel/extensions'" ~/build/rails/activerecord/test/cases/helper.rb
35
+ - "sed -i \"/group :db do/a gem 'arel-extensions', require: 'arel/extensions', path: File.expand_path\\('~\\/build\\/malomalo\\/arel-extensions'\\)\" ~/build/rails/Gemfile"
36
+ - sed -i "/rb-inotify/d" ~/build/rails/Gemfile
37
+ - cat ~/build/rails/Gemfile
38
+ - bundle install --jobs=3 --retry=3
39
+ - popd
40
+
41
+ script:
42
+ - cd ~/build/rails && ci/travis.rb
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = 'arel-extensions'
3
- gem.version = '1.5.2'
3
+ gem.version = '1.6.0'
4
4
 
5
5
  gem.authors = ["Jon Bracy"]
6
6
  gem.email = ["jonbracy@gmail.com"]
@@ -12,7 +12,7 @@ Gem::Specification.new do |gem|
12
12
  gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
13
13
  gem.require_paths = ["lib"]
14
14
 
15
- gem.add_dependency 'arel', '>= 7.0.0'
15
+ gem.add_dependency 'arel', '>= 9.0.0'
16
16
 
17
17
  gem.add_development_dependency 'rake'
18
18
  gem.add_development_dependency 'minitest'
@@ -24,8 +24,8 @@ module ActiveRecord::QueryMethods
24
24
  end
25
25
  alias uniq_on! distinct_on!
26
26
 
27
- def build_arel_with_distinct_on
28
- arel = build_arel_without_distinct_on
27
+ def build_arel_with_distinct_on(aliases)
28
+ arel = build_arel_without_distinct_on(aliases)
29
29
  arel.distinct_on(self.distinct_on_values) if !self.distinct_on_values.empty?
30
30
  arel
31
31
  end
@@ -1,5 +1,8 @@
1
+ require File.expand_path('../nodes/hex_encoded_binary', __FILE__)
2
+
1
3
  require File.expand_path('../nodes/overlaps', __FILE__)
2
4
  require File.expand_path('../nodes/contains', __FILE__)
5
+ require File.expand_path('../nodes/within', __FILE__)
3
6
  require File.expand_path('../nodes/excludes', __FILE__)
4
7
  require File.expand_path('../nodes/contained_by', __FILE__)
5
8
  require File.expand_path('../array_predications', __FILE__)
@@ -1,29 +1,9 @@
1
1
  module Arel
2
2
  module GISPredications
3
3
 
4
- def within(n=nil, e=nil, s=nil, w=nil)
5
- if n.class.to_s == 'String' && e.nil?
6
- within(*n.split(','))
7
- elsif n.is_a?(Array)
8
- within(*n)
9
- elsif n.is_a?(Hash)
10
- if (n.keys - [:n, :e, :s, :w]).empty?
11
- within(n[:n], n[:e], n[:s], n[:w])
12
- elsif (n.keys - [:north, :east, :south, :west]).empty?
13
- within(n[:north], n[:east], n[:south], n[:west])
14
- else
15
- radius = n[:radius] * 1609.34
16
- point_args = [point[:longitude], point[:latitude], radius].map { |x| Arel::Nodes.build_quoted(x) }
17
- point = Arel::Nodes::NamedFunction.new('ST_MakePoint', point_args).cast_as('geography')
18
- Arel::Nodes::NamedFunction.new('ST_DWithin', [self, point, radius])
19
- end
20
- else
21
- make_envelope_args = [w, s, e, n, 4326].map { |x| Arel::Nodes.build_quoted(x) }
22
- envelope = Arel::Nodes::NamedFunction.new('ST_MakeEnvelope', make_envelope_args)
23
- # Arel::Nodes::NamedFunction.new('ST_Contains', [envelope, self])
24
- Arel::Nodes::NamedFunction.new('ST_Within', [self, envelope])
25
- end
4
+ def within(bounds)
5
+ Arel::Nodes::Within.new(self, bounds)
26
6
  end
27
7
 
28
8
  end
29
- end
9
+ end
@@ -16,7 +16,7 @@ module Arel
16
16
  end
17
17
 
18
18
  def has_any_key(*keys)
19
- Arel::Nodes::HasAnyKeys.new(self, keys)
19
+ Arel::Nodes::HasAnyKey.new(self, keys)
20
20
  end
21
21
 
22
22
  def cast_as(type)
@@ -1,6 +1,6 @@
1
1
  module Arel
2
2
  module Nodes
3
- class HasAnyKeys < Binary
3
+ class HasAnyKey < Binary
4
4
  # ?|
5
5
  end
6
6
  end
@@ -0,0 +1,7 @@
1
+ module Arel
2
+ module Nodes
3
+ class HexEncodedBinary < Unary
4
+
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ module Arel
2
+ module Nodes
3
+ class Within < Binary
4
+ end
5
+ end
6
+ end
@@ -64,6 +64,24 @@ module Arel
64
64
  collector << " ? " << quote(right.to_s)
65
65
  collector
66
66
  end
67
+
68
+ def visit_Arel_Nodes_HasKeys(o, collector)
69
+ right = o.right
70
+
71
+ collector = visit o.left, collector
72
+
73
+ collector << " ?& array[" << Array(right).map { |v| quote(v.to_s) }.join(',') << "]"
74
+ collector
75
+ end
76
+
77
+ def visit_Arel_Nodes_HasAnyKey(o, collector)
78
+ right = o.right
79
+
80
+ collector = visit o.left, collector
81
+
82
+ collector << " ?| array[" << Array(right).map { |v| quote(v.to_s) }.join(',') << "]"
83
+ collector
84
+ end
67
85
 
68
86
  def visit_Arel_Attributes_Cast(o, collector)
69
87
  collector << "("
@@ -100,6 +118,28 @@ module Arel
100
118
  collector << ')'
101
119
  collector
102
120
  end
121
+
122
+ def visit_Arel_Nodes_HexEncodedBinary(o, collector)
123
+ collector << "E'\\\\x"
124
+ collector << o.expr
125
+ collector << "'"
126
+ collector
127
+ end
128
+
129
+ def visit_Arel_Nodes_Within o, collector
130
+ envelope = if o.right.is_a?(Arel::Nodes::HexEncodedBinary)
131
+ Arel::Nodes::NamedFunction.new('ST_GeomFromEWKB', [o.right])
132
+ elsif o.right.is_a?(Arel::Nodes::Quoted) && o.right.expr.is_a?(String)
133
+ Arel::Nodes::NamedFunction.new('ST_GeomFromEWKT', [o.right])
134
+ elsif o.right.is_a?(Arel::Nodes::Quoted) && o.right.expr.is_a?(Hash)
135
+ Arel::Nodes::NamedFunction.new('ST_GeomFromGeoJSON', [Arel::Nodes.build_quoted(o.right.expr.to_json)])
136
+ else
137
+ raise 'within error'
138
+ end
139
+
140
+ visit(Arel::Nodes::NamedFunction.new('ST_Within', [o.left, envelope]), collector)
141
+ collector
142
+ end
103
143
 
104
144
  end
105
145
  end
@@ -5,7 +5,7 @@ module Arel
5
5
 
6
6
  def visit_Arel_Nodes_Contains o, collector
7
7
  key = visit(o.left, collector)
8
- value = { contains: visit(o.right, collector) }
8
+ value = { contains: visit(o.right, collector) }
9
9
 
10
10
  if key.is_a?(Hash)
11
11
  add_to_bottom_of_hash(key, value)
@@ -14,6 +14,21 @@ module Arel
14
14
  end
15
15
  end
16
16
 
17
+ def visit_Arel_Nodes_HexEncodedBinary(o, collector)
18
+ o.expr
19
+ end
20
+
21
+ def visit_Arel_Nodes_Within o, collector
22
+ key = visit(o.left, collector)
23
+ value = { within: visit(o.right, collector) }
24
+
25
+ if key.is_a?(Hash)
26
+ add_to_bottom_of_hash(key, value)
27
+ else
28
+ { key => value }
29
+ end
30
+ end
31
+
17
32
  def visit_Arel_Nodes_Excludes o, collector
18
33
  key = visit(o.left, collector)
19
34
  value = { excludes: o.left.type_cast_for_database(o.right) }
@@ -25,6 +40,39 @@ module Arel
25
40
  end
26
41
  end
27
42
 
43
+ def visit_Arel_Nodes_HasKey o, collector
44
+ key = visit(o.left, collector)
45
+ value = {has_key: (o.right.nil? ? nil : o.right.to_s)}
46
+
47
+ if key.is_a?(Hash)
48
+ add_to_bottom_of_hash(key, value)
49
+ else
50
+ { key => value }
51
+ end
52
+ end
53
+
54
+ def visit_Arel_Nodes_HasKeys o, collector
55
+ key = visit(o.left, collector)
56
+ value = {has_keys: Array(o.right).map(&:to_s)}
57
+
58
+ if key.is_a?(Hash)
59
+ add_to_bottom_of_hash(key, value)
60
+ else
61
+ { key => value }
62
+ end
63
+ end
64
+
65
+ def visit_Arel_Nodes_HasAnyKey o, collector
66
+ key = visit(o.left, collector)
67
+ value = {has_any_key: Array(o.right).map(&:to_s)}
68
+
69
+ if key.is_a?(Hash)
70
+ add_to_bottom_of_hash(key, value)
71
+ else
72
+ { key => value }
73
+ end
74
+ end
75
+
28
76
  end
29
77
  end
30
78
  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: 1.5.2
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Bracy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-14 00:00:00.000000000 Z
11
+ date: 2018-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: arel
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 7.0.0
19
+ version: 9.0.0
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: 7.0.0
26
+ version: 9.0.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -59,6 +59,7 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
+ - ".travis.yml"
62
63
  - LICENSE
63
64
  - README.md
64
65
  - arel-extensions.gemspec
@@ -75,10 +76,12 @@ files:
75
76
  - lib/arel/nodes/has_any_key.rb
76
77
  - lib/arel/nodes/has_key.rb
77
78
  - lib/arel/nodes/has_keys.rb
79
+ - lib/arel/nodes/hex_encoded_binary.rb
78
80
  - lib/arel/nodes/overlaps.rb
79
81
  - lib/arel/nodes/ts_match.rb
80
82
  - lib/arel/nodes/ts_query.rb
81
83
  - lib/arel/nodes/ts_vector.rb
84
+ - lib/arel/nodes/within.rb
82
85
  - lib/arel/ts_predications.rb
83
86
  - lib/arel/visitors/postgresql_extensions.rb
84
87
  - lib/arel/visitors/sunstone_extensions.rb
@@ -102,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
105
  version: '0'
103
106
  requirements: []
104
107
  rubyforge_project:
105
- rubygems_version: 2.6.8
108
+ rubygems_version: 2.7.4
106
109
  signing_key:
107
110
  specification_version: 4
108
111
  summary: Adds support for missing SQL operators and functions to Arel