arel-extensions 1.4.0 → 1.5.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
  SHA1:
3
- metadata.gz: 93c939760cdc803cc6bbedb950ebb9ce9ca39610
4
- data.tar.gz: ff6576c5f315d326dbd4e25a7f76d06df2159a67
3
+ metadata.gz: 608dab3c15e77d6dd8ee5c39d54b442886f67cf4
4
+ data.tar.gz: d2fb99dc3fc50b3668cb192561883284891fc2e1
5
5
  SHA512:
6
- metadata.gz: 4808b1ca2d55f753f32952883252797135193882afd328456e410db83960db3ed21342eafd9639bb15e11b7c33913bd931cbe3d60d83d3edbf71d400a2f40149
7
- data.tar.gz: f071b4ea0c5f8887d283afed3be26be4a2e9cc361a13ea1b62fec88c051d8575b213ad5e4fc773be7618fc2ced3c510afc882700b4a4c57e9f3287d4c7dd205a
6
+ metadata.gz: db29b2210f174795a094f396f76d031e373c6391e13030e17ef2a24ec6eb840ae58c870acf863251c01053c9784332a72e8b477fbf744042720e7f36b5141575
7
+ data.tar.gz: 6b059b8c0c0fa4a6961c969cb6798ea2de47ed904381d0b73d48a8362dc516b4f2cc2c2be55c7b2c4f1907df227cc37b11ccf1dd9e1e33651ea57a41f30af4cd
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = 'arel-extensions'
3
- gem.version = '1.4.0'
3
+ gem.version = '1.5.0'
4
4
 
5
5
  gem.authors = ["Jon Bracy"]
6
6
  gem.email = ["jonbracy@gmail.com"]
@@ -19,6 +19,10 @@ require File.expand_path('../nodes/ts_match', __FILE__)
19
19
  require File.expand_path('../ts_predications', __FILE__)
20
20
  Arel::Attributes::Attribute.include(Arel::TSPredications)
21
21
 
22
+
23
+ require File.expand_path('../gis_predications', __FILE__)
24
+ Arel::Attributes::Attribute.include(Arel::GISPredications)
25
+
22
26
  require File.expand_path('../../active_record/query_methods', __FILE__)
23
27
 
24
28
  if defined?(Arel::Visitors::PostgreSQL)
@@ -0,0 +1,29 @@
1
+ module Arel
2
+ module GISPredications
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
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,6 @@
1
+ module Arel
2
+ module Nodes
3
+ class Excludes < Binary
4
+ end
5
+ end
6
+ end
@@ -22,6 +22,15 @@ module Arel
22
22
  collector
23
23
  end
24
24
 
25
+ def visit_Arel_Nodes_Excludes o, collector
26
+ collector << 'NOT ('
27
+ visit o.left, collector
28
+ collector << ' @> '
29
+ collector << quote(o.left.type_cast_for_database(o.right))
30
+ collector << ')'
31
+ collector
32
+ end
33
+
25
34
  def visit_Arel_Nodes_Overlaps o, collector
26
35
  visit o.left, collector
27
36
  collector << ' && '
@@ -5,17 +5,23 @@ 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)
12
12
  else
13
- key = key.to_s.split('.')
14
- hash = { key.pop => value }
15
- while key.size > 0
16
- hash = { key.pop => hash }
17
- end
18
- hash
13
+ { key => value }
14
+ end
15
+ end
16
+
17
+ def visit_Arel_Nodes_Excludes o, collector
18
+ key = visit(o.left, collector)
19
+ value = { excludes: visit(o.right, collector) }
20
+
21
+ if key.is_a?(Hash)
22
+ add_to_bottom_of_hash(key, value)
23
+ else
24
+ { key => value }
19
25
  end
20
26
  end
21
27
 
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.4.0
4
+ version: 1.5.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-01 00:00:00.000000000 Z
11
+ date: 2017-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: arel
@@ -67,9 +67,11 @@ files:
67
67
  - lib/arel/attributes/cast.rb
68
68
  - lib/arel/attributes/key.rb
69
69
  - lib/arel/extensions.rb
70
+ - lib/arel/gis_predications.rb
70
71
  - lib/arel/json_predications.rb
71
72
  - lib/arel/nodes/contained_by.rb
72
73
  - lib/arel/nodes/contains.rb
74
+ - lib/arel/nodes/excludes.rb
73
75
  - lib/arel/nodes/has_any_key.rb
74
76
  - lib/arel/nodes/has_key.rb
75
77
  - lib/arel/nodes/has_keys.rb