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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/raspy.rb +67 -9
  3. data/lib/raspy/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2e0f6f53510865ebb5a3dc83fd4c9388c8457bfc
4
- data.tar.gz: eeb221b9af953b29a9bf7c27826e9940af673702
3
+ metadata.gz: d61b47c7c0684689fea54470e584a0b374ac341f
4
+ data.tar.gz: a620c80ecb7ee31686cced32b89f0ca26c958880
5
5
  SHA512:
6
- metadata.gz: 2d9710d5e677776666a5c4a40473b9a51a6705c8671582a6a5224b54160d29a33db9316ce65997fcf19c751e8212d0bb98e335b831b40a6b6a1e90851fe4ec8e
7
- data.tar.gz: 1f33d9fd06883d649cc4ed8df932b41e1c37a35bc1eca1af341f344a4d560ff7e70d27f5a9846dcc401abc1de477e11b49b01fb39d50186f8c63e953b08f87d4
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
@@ -1,3 +1,3 @@
1
1
  module Raspy
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: raspy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ajith Hussain