raspy 1.0.2 → 1.0.3
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.
- checksums.yaml +4 -4
- data/lib/raspy.rb +67 -9
- data/lib/raspy/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d61b47c7c0684689fea54470e584a0b374ac341f
|
4
|
+
data.tar.gz: a620c80ecb7ee31686cced32b89f0ca26c958880
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc9e7389520a088fd2da53432d9acbc69d1384798fa36908e9f8c433b2dc1d0a35be2ddf32676740b52fe2d6e175efa3e2a2d97564505584159effcee90e0a4f
|
7
|
+
data.tar.gz: 2417a420eb3e0032c07f1c15b75a02a021a92150fb11aa9f1ca65bb5f2c4bb0f9cc4b382d85688afb5b12853ac5b4bdbb72515a9e6ee84428f87de393121992a
|
data/lib/raspy.rb
CHANGED
@@ -15,18 +15,9 @@ class ActiveRecord::Base
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
class Array
|
19
|
-
def prefetch(args)
|
20
|
-
return if args.keys.length == 0
|
21
|
-
|
22
|
-
raise Raspy::Error.new("Cannot run prefetch on a non-uniform list") unless self.map(&:class).uniq.length == 1
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
18
|
module Raspy
|
27
19
|
extend Rusql
|
28
20
|
|
29
|
-
|
30
21
|
def self.preload_habtm(list:, name:, association_klass:, foreign_key:, association_foreign_key:, inner_associations:, join_table:, association_condition:)
|
31
22
|
return if list.nil? || list.length == 0
|
32
23
|
|
@@ -248,3 +239,70 @@ module Raspy
|
|
248
239
|
end
|
249
240
|
end
|
250
241
|
end
|
242
|
+
|
243
|
+
class Array
|
244
|
+
def prefetch(args)
|
245
|
+
return if args.keys.length == 0
|
246
|
+
|
247
|
+
args.each_pair do |name, details|
|
248
|
+
raise Raspy::Error.new("Incomplete relation details for '#{name}'") unless \
|
249
|
+
details.is_a?(Hash) \
|
250
|
+
&& details[:type].present?
|
251
|
+
|
252
|
+
case details[:type]
|
253
|
+
when :belongs_to, "belongs_to"
|
254
|
+
Raspy.preload_belongs_to(
|
255
|
+
list: self,
|
256
|
+
name: name,
|
257
|
+
association_klass: details[:klass],
|
258
|
+
foreign_key: details[:foreign_key],
|
259
|
+
inner_associations: details[:associations],
|
260
|
+
additional_selects: details[:additional_selects] || [],
|
261
|
+
additional_joins: details[:additional_joins] || [],
|
262
|
+
association_condition: details[:association_condition]
|
263
|
+
)
|
264
|
+
when :polymorphic_belongs_to, "polymorphic_belongs_to"
|
265
|
+
Raspy.preload_polymorphic_belongs_to(
|
266
|
+
list: self,
|
267
|
+
name: name,
|
268
|
+
polymorphic_key_field: details[:polymorphic_key_field],
|
269
|
+
polymorphic_type_field: details[:polymorphic_type_field],
|
270
|
+
polymorphic_type_map: details[:polymorphic_type_map]
|
271
|
+
)
|
272
|
+
when :has_one, "has_one"
|
273
|
+
Raspy.preload_has_one(
|
274
|
+
list: self,
|
275
|
+
name: name,
|
276
|
+
association_klass: details[:klass],
|
277
|
+
foreign_key: details[:foreign_key],
|
278
|
+
order_type: details[:order_type],
|
279
|
+
order_field: details[:order_field],
|
280
|
+
inner_associations: details[:associations],
|
281
|
+
association_condition: details[:association_condition],
|
282
|
+
reverse_association: details[:reverse_association]
|
283
|
+
)
|
284
|
+
when :has_many, "has_many"
|
285
|
+
Raspy.preload_has_many(
|
286
|
+
list: self,
|
287
|
+
name: name,
|
288
|
+
association_klass: details[:klass],
|
289
|
+
foreign_key: details[:foreign_key],
|
290
|
+
inner_associations: details[:associations],
|
291
|
+
association_condition: details[:association_condition],
|
292
|
+
reverse_association: details[:reverse_association]
|
293
|
+
)
|
294
|
+
when :has_and_belongs_to_many, "has_and_belongs_to_many"
|
295
|
+
Raspy.preload_habtm(
|
296
|
+
list: self,
|
297
|
+
name: name,
|
298
|
+
association_klass: details[:klass],
|
299
|
+
foreign_key: details[:foreign_key],
|
300
|
+
association_foreign_key: details[:association_foreign_key],
|
301
|
+
inner_associations: details[:associations],
|
302
|
+
join_table: details[:join_table],
|
303
|
+
association_condition: details[:association_condition]
|
304
|
+
)
|
305
|
+
end
|
306
|
+
end
|
307
|
+
end
|
308
|
+
end
|
data/lib/raspy/version.rb
CHANGED