ar_pg_array 0.9.9 → 0.9.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/ar_pg_array/querying_arel.rb +104 -39
- data/spec/spec_helper.rb +1 -0
- metadata +5 -8
data/Rakefile
CHANGED
@@ -30,7 +30,7 @@ begin
|
|
30
30
|
gemspec.email = "funny.falcon@gmail.com"
|
31
31
|
gemspec.homepage = "http://github.com/funny-falcon/activerecord-postgresql-arrays"
|
32
32
|
gemspec.authors = ["Sokolov Yura aka funny_falcon"]
|
33
|
-
gemspec.add_dependency('
|
33
|
+
gemspec.add_dependency('activerecord', '>= 2.3.5')
|
34
34
|
gemspec.rubyforge_project = 'ar-pg-array'
|
35
35
|
end
|
36
36
|
Jeweler::GemcutterTasks.new
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.9.
|
1
|
+
0.9.12
|
@@ -119,51 +119,116 @@ else
|
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
122
|
+
if ActiveRecord::VERSION::STRING < '3.1'
|
123
|
+
module ActiveRecord
|
124
|
+
class PredicateBuilder
|
125
|
+
def build_from_hash(attributes, default_table)
|
126
|
+
predicates = attributes.map do |column, value|
|
127
|
+
table = default_table
|
128
|
+
|
129
|
+
if value.is_a?(Hash)
|
130
|
+
table = Arel::Table.new(column, :engine => @engine)
|
131
|
+
build_from_hash(value, table)
|
132
|
+
else
|
133
|
+
column = column.to_s
|
134
|
+
|
135
|
+
if column.include?('.')
|
136
|
+
table_name, column = column.split('.', 2)
|
137
|
+
table = Arel::Table.new(table_name, :engine => @engine)
|
138
|
+
end
|
139
|
+
|
140
|
+
attribute = table[column] || Arel::Attribute.new(table, column)
|
141
|
+
|
142
|
+
case value
|
143
|
+
when PGArrays::PgAny
|
144
|
+
attribute.ar_any(value)
|
145
|
+
when PGArrays::PgAll
|
146
|
+
attribute.ar_all(value)
|
147
|
+
when PGArrays::PgIncludes
|
148
|
+
attribute.ar_included(value)
|
149
|
+
when Array, ActiveRecord::Associations::AssociationCollection, ActiveRecord::Relation
|
150
|
+
values = value.to_a.map { |x|
|
151
|
+
x.is_a?(ActiveRecord::Base) ? x.id : x
|
152
|
+
}
|
153
|
+
attribute.in(values)
|
154
|
+
when Range, Arel::Relation
|
155
|
+
attribute.in(value)
|
156
|
+
when ActiveRecord::Base
|
157
|
+
attribute.eq(value.id)
|
158
|
+
when Class
|
159
|
+
# FIXME: I think we need to deprecate this behavior
|
160
|
+
attribute.eq(value.name)
|
161
|
+
else
|
162
|
+
attribute.eq(value)
|
163
|
+
end
|
137
164
|
end
|
165
|
+
end
|
138
166
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
when Range, Arel::Relation
|
154
|
-
attribute.in(value)
|
155
|
-
when ActiveRecord::Base
|
156
|
-
attribute.eq(value.id)
|
157
|
-
when Class
|
158
|
-
# FIXME: I think we need to deprecate this behavior
|
159
|
-
attribute.eq(value.name)
|
167
|
+
predicates.flatten
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
else
|
172
|
+
module ActiveRecord
|
173
|
+
class PredicateBuilder
|
174
|
+
def self.build_from_hash(engine, attributes, default_table)
|
175
|
+
predicates = attributes.map do |column, value|
|
176
|
+
table = default_table
|
177
|
+
|
178
|
+
if value.is_a?(Hash)
|
179
|
+
table = Arel::Table.new(column, engine)
|
180
|
+
build_from_hash(engine, value, table)
|
160
181
|
else
|
161
|
-
|
182
|
+
column = column.to_s
|
183
|
+
|
184
|
+
if column.include?('.')
|
185
|
+
table_name, column = column.split('.', 2)
|
186
|
+
table = Arel::Table.new(table_name, engine)
|
187
|
+
end
|
188
|
+
|
189
|
+
attribute = table[column.to_sym]
|
190
|
+
|
191
|
+
case value
|
192
|
+
when PGArrays::PgAny
|
193
|
+
attribute.ar_any(value)
|
194
|
+
when PGArrays::PgAll
|
195
|
+
attribute.ar_all(value)
|
196
|
+
when PGArrays::PgIncludes
|
197
|
+
attribute.ar_included(value)
|
198
|
+
when ActiveRecord::Relation
|
199
|
+
value = value.select(value.klass.arel_table[value.klass.primary_key]) if value.select_values.empty?
|
200
|
+
attribute.in(value.arel.ast)
|
201
|
+
when Array, ActiveRecord::Associations::CollectionProxy
|
202
|
+
values = value.to_a.map { |x|
|
203
|
+
x.is_a?(ActiveRecord::Base) ? x.id : x
|
204
|
+
}
|
205
|
+
|
206
|
+
if values.include?(nil)
|
207
|
+
values = values.compact
|
208
|
+
if values.empty?
|
209
|
+
attribute.eq nil
|
210
|
+
else
|
211
|
+
attribute.in(values.compact).or attribute.eq(nil)
|
212
|
+
end
|
213
|
+
else
|
214
|
+
attribute.in(values)
|
215
|
+
end
|
216
|
+
|
217
|
+
when Range, Arel::Relation
|
218
|
+
attribute.in(value)
|
219
|
+
when ActiveRecord::Base
|
220
|
+
attribute.eq(value.id)
|
221
|
+
when Class
|
222
|
+
# FIXME: I think we need to deprecate this behavior
|
223
|
+
attribute.eq(value.name)
|
224
|
+
else
|
225
|
+
attribute.eq(value)
|
226
|
+
end
|
162
227
|
end
|
163
228
|
end
|
164
|
-
end
|
165
229
|
|
166
|
-
|
230
|
+
predicates.flatten
|
231
|
+
end
|
167
232
|
end
|
168
233
|
end
|
169
234
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -44,6 +44,7 @@ ActiveRecord::Base.silence do
|
|
44
44
|
# load schema
|
45
45
|
load File.join('spec/fixtures/schema.rb')
|
46
46
|
# load fixtures
|
47
|
+
Fixtures = ActiveRecord::Fixtures unless defined?(Fixtures)
|
47
48
|
Fixtures.create_fixtures("spec/fixtures", ActiveRecord::Base.connection.tables)
|
48
49
|
end
|
49
50
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ar_pg_array
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.12
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,22 +9,19 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-12-
|
12
|
+
date: 2011-12-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
16
|
-
requirement: &
|
15
|
+
name: activerecord
|
16
|
+
requirement: &84412580 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- - <
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: '3.1'
|
22
19
|
- - ! '>='
|
23
20
|
- !ruby/object:Gem::Version
|
24
21
|
version: 2.3.5
|
25
22
|
type: :runtime
|
26
23
|
prerelease: false
|
27
|
-
version_requirements: *
|
24
|
+
version_requirements: *84412580
|
28
25
|
description: ar_pg_array includes support of PostgreSQL's int[], float[], text[],
|
29
26
|
timestamptz[] etc. into ActiveRecord. You could define migrations for array columns,
|
30
27
|
query on array columns.
|