arel-extensions 1.0.0 → 1.1.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: 4847138fb20c8ca58e5bf419b595e1cf9e4dc809
4
- data.tar.gz: 54565109b15574583361a153a2558bdb5deac376
3
+ metadata.gz: 3c79633129067dda19ceaeaf6f0241b23d57c804
4
+ data.tar.gz: 7f401572e73ed1e40cde5f094360d427bd7539c1
5
5
  SHA512:
6
- metadata.gz: d934dc0afa953e09db3837747ebc919ae473901f6da32033a76635261eda113c75504a7ac98c861b48983993c2e0dace2f439f31d18542b62e01ce30b1d66d74
7
- data.tar.gz: f568ff754c5f16fca13c73925353ffe9aae53fcd1cdfa8da74dafebabef5110c0308135375241c8c82e7bb2f420229da4ec41bdc3d9b99e055215d387a988ae6
6
+ metadata.gz: d306bc36f6b25224da947efc251686455e7353f67bc9af65ba7f81df704838ff640c0fe5f6d030f5a33cfffbc5e5f51885caba4c715231072463d24582b7a602
7
+ data.tar.gz: d802003762477a56fde5f2e7f7b08c4dbbdab73cc0f448d5915a953cdfe8ce5562bb1e7aa785876f8069eda3b1e8487461a8c3aa8488e16293c36cd9487cbd0f
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = 'arel-extensions'
3
- gem.version = '1.0.0'
3
+ gem.version = '1.1.0'
4
4
 
5
5
  gem.authors = ["Jon Bracy"]
6
6
  gem.email = ["jonbracy@gmail.com"]
@@ -0,0 +1,14 @@
1
+ module Arel
2
+ module Attributes
3
+ class Cast < Attribute
4
+
5
+ def able_to_type_cast?
6
+ false
7
+ end
8
+
9
+ def table_name
10
+ nil
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,6 +1,7 @@
1
1
  module Arel
2
2
  module Attributes
3
3
  class Key < Attribute
4
+
4
5
  def able_to_type_cast?
5
6
  false
6
7
  end
@@ -1,16 +1,27 @@
1
- require File.expand_path('../array_predications', __FILE__)
2
1
  require File.expand_path('../nodes/overlaps', __FILE__)
3
2
  require File.expand_path('../nodes/contains', __FILE__)
3
+ require File.expand_path('../array_predications', __FILE__)
4
4
  Arel::Attributes::Attribute.include(Arel::ArrayPredications)
5
5
 
6
6
 
7
7
  require File.expand_path('../attributes/key', __FILE__)
8
+ require File.expand_path('../attributes/cast', __FILE__)
8
9
  require File.expand_path('../nodes/has_any_key', __FILE__)
9
10
  require File.expand_path('../nodes/has_key', __FILE__)
10
11
  require File.expand_path('../nodes/has_keys', __FILE__)
11
12
  require File.expand_path('../json_predications', __FILE__)
12
13
  Arel::Attributes::Attribute.include(Arel::JSONPredications)
13
14
 
15
+ require File.expand_path('../nodes/ts_vector', __FILE__)
16
+ require File.expand_path('../nodes/ts_query', __FILE__)
17
+ require File.expand_path('../nodes/ts_match', __FILE__)
18
+ require File.expand_path('../ts_predications', __FILE__)
19
+ Arel::Attributes::Attribute.include(Arel::TSPredications)
20
+
14
21
  if defined?(Arel::Visitors::PostgreSQL)
15
22
  require File.expand_path('../visitors/postgresql_extensions', __FILE__)
23
+ end
24
+
25
+ if defined?(Arel::Visitors::Sunstone)
26
+ require File.expand_path('../visitors/sunstone_extensions', __FILE__)
16
27
  end
@@ -19,5 +19,9 @@ module Arel
19
19
  Arel::Nodes::HasAnyKeys.new(self, keys)
20
20
  end
21
21
 
22
+ def cast_as(type)
23
+ Arel::Attributes::Cast.new(self, type)
24
+ end
25
+
22
26
  end
23
27
  end
@@ -0,0 +1,6 @@
1
+ module Arel
2
+ module Nodes
3
+ class TSMatch < Binary
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,14 @@
1
+ module Arel
2
+ module Nodes
3
+ class TSQuery < Arel::Nodes::Node
4
+
5
+ attr_reader :expression, :language
6
+
7
+ def initialize(expression, language)
8
+ @expression = Arel::Nodes.build_quoted(expression)
9
+ @language = Arel::Nodes.build_quoted(language) if language
10
+ end
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ module Arel
2
+ module Nodes
3
+ class TSVector < Arel::Nodes::Node
4
+
5
+ attr_reader :attribute, :language
6
+
7
+ def initialize(attribute, language)
8
+ @attribute = attribute
9
+ @language = Arel::Nodes.build_quoted(language) if language
10
+ end
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ module Arel
2
+ module TSPredications
3
+
4
+ def ts_query(expression, language=nil)
5
+ vector = Arel::Nodes::TSVector.new(self, language)
6
+ query = Arel::Nodes::TSQuery.new(expression, language)
7
+
8
+ Arel::Nodes::TSMatch.new(vector, query)
9
+ end
10
+
11
+ end
12
+ end
@@ -3,22 +3,30 @@ module Arel
3
3
  class PostgreSQL
4
4
  private
5
5
 
6
+ def column_for attr
7
+ return nil if attr.is_a?(Arel::Attributes::Key)
8
+ super
9
+ end
10
+
6
11
  def visit_Arel_Nodes_Contains o, collector
7
12
  visit o.left, collector
8
13
  collector << ' @> '
9
14
  collector << quote(o.left.type_cast_for_database(o.right))
15
+ collector
10
16
  end
11
17
 
12
18
  def visit_Arel_Nodes_ContainedBy o, collector
13
19
  visit o.left, collector
14
20
  collector << ' <@ '
15
21
  collector << quote(o.left.type_cast_for_database(o.right))
22
+ collector
16
23
  end
17
24
 
18
25
  def visit_Arel_Nodes_Overlaps o, collector
19
26
  visit o.left, collector
20
27
  collector << ' && '
21
28
  collector << quote(o.left.type_cast_for_database(o.right))
29
+ collector
22
30
  end
23
31
 
24
32
  def visit_Arel_Attributes_Key(o, collector, last_key = true)
@@ -29,17 +37,61 @@ module Arel
29
37
  collector << "}'"
30
38
  else
31
39
  collector << o.name.to_s
32
- collector << "."
40
+ collector << ","
33
41
  end
34
42
  else
35
43
  visit(o.relation, collector)
36
44
  collector << "\#>>'{" << o.name.to_s
37
- if !last_key
38
- collector << "."
39
- end
45
+ collector << (last_key ? "}'" : ",")
46
+ end
47
+ collector
48
+ end
49
+
50
+ def visit_Arel_Nodes_HasKey(o, collector)
51
+ right = o.right
52
+
53
+ collector = visit o.left, collector
54
+
55
+ collector << " ? " << quote(right.to_s)
56
+ collector
57
+ end
58
+
59
+ def visit_Arel_Attributes_Cast(o, collector)
60
+ collector << "("
61
+ visit(o.relation, collector)
62
+ collector << ")::#{o.name}"
63
+ collector
64
+ end
65
+
66
+ def visit_Arel_Nodes_TSMatch(o, collector)
67
+ visit o.left, collector
68
+ collector << ' @@ '
69
+ visit o.right, collector
70
+ collector
71
+ end
72
+
73
+ def visit_Arel_Nodes_TSVector(o, collector)
74
+ collector << 'to_tsvector('
75
+ if o.language
76
+ visit(o.language, collector)
77
+ collector << ', '
40
78
  end
79
+ visit(o.attribute, collector)
80
+ collector << ')'
81
+ collector
41
82
  end
42
83
 
84
+ def visit_Arel_Nodes_TSQuery(o, collector)
85
+ collector << 'to_tsquery('
86
+ if o.language
87
+ visit(o.language, collector)
88
+ collector << ', '
89
+ end
90
+ visit(o.expression, collector)
91
+ collector << ')'
92
+ collector
93
+ end
94
+
43
95
  end
44
96
  end
45
97
  end
@@ -0,0 +1,24 @@
1
+ module Arel
2
+ module Visitors
3
+ class Sunstone
4
+ private
5
+
6
+ def visit_Arel_Nodes_Contains o, collector
7
+ key = visit(o.left, collector)
8
+ value = { :contains => visit(o.right, collector) }
9
+
10
+ if key.is_a?(Hash)
11
+ add_to_bottom_of_hash(key, value)
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
19
+ end
20
+ end
21
+
22
+ end
23
+ end
24
+ 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.0.0
4
+ version: 1.1.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: 2016-02-06 00:00:00.000000000 Z
11
+ date: 2016-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: arel
@@ -63,6 +63,7 @@ files:
63
63
  - README.md
64
64
  - arel-extensions.gemspec
65
65
  - lib/arel/array_predications.rb
66
+ - lib/arel/attributes/cast.rb
66
67
  - lib/arel/attributes/key.rb
67
68
  - lib/arel/extensions.rb
68
69
  - lib/arel/json_predications.rb
@@ -71,7 +72,12 @@ files:
71
72
  - lib/arel/nodes/has_key.rb
72
73
  - lib/arel/nodes/has_keys.rb
73
74
  - lib/arel/nodes/overlaps.rb
75
+ - lib/arel/nodes/ts_match.rb
76
+ - lib/arel/nodes/ts_query.rb
77
+ - lib/arel/nodes/ts_vector.rb
78
+ - lib/arel/ts_predications.rb
74
79
  - lib/arel/visitors/postgresql_extensions.rb
80
+ - lib/arel/visitors/sunstone_extensions.rb
75
81
  homepage: https://github.com/malomalo/arel-extensions
76
82
  licenses:
77
83
  - MIT
@@ -92,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
98
  version: '0'
93
99
  requirements: []
94
100
  rubyforge_project:
95
- rubygems_version: 2.5.1
101
+ rubygems_version: 2.6.4
96
102
  signing_key:
97
103
  specification_version: 4
98
104
  summary: Adds support for missing SQL operators and functions to Arel