web-connect 0.4.4 → 0.4.5

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: 9a78c316aa0dd58c987d6a68648bdf9d2af9f851
4
- data.tar.gz: 41e0fb236184473185bbd711308fe1a87ed9810d
3
+ metadata.gz: f63aefe6e3d4e57c35a13b8d50c498cd4f251af7
4
+ data.tar.gz: cb70abe3467ee489bf9f3360575ce59304d2a420
5
5
  SHA512:
6
- metadata.gz: 6eab39887c6b60a94689193dc3d0cb167f7e32c37d76eee2b1803b013db5819413c643b26d3bf25b6d0762f4ae83c9baae5b1c61399597cb2548fa943fa36b3e
7
- data.tar.gz: 696ab4061e29e06d5c394c087476a3e20540c00e5b66c84a20123990771f4a2c3119be3780d58bc391d76d4b02e3af137acdaeec7f36a4a15449e63de13753f1
6
+ metadata.gz: c24950ca0f415a5281c454952ed7b16df6822af7e2a3e5b296c6db10be5b2281e7917f4e737db8759ce0852a868c6607664bdde658b7482c03b9128a58250af0
7
+ data.tar.gz: 1103b12151704ba54c8e69f707d7aa5b07174e49c6abc6e92949ea5b09bbac33efc7e2c86c614cdfc3a23cbfa7f40a877631a2846d549e2f992ccacf84dd4ce3
@@ -10,11 +10,11 @@ module Netfira::WebConnect
10
10
 
11
11
  def materialize(name_a, name_b)
12
12
 
13
- # The new class, e.g. Models::CategoryToProduct
13
+ # The new class, e.g. Models::ImageToProduct
14
14
  klass = Class.new(self)
15
15
  Models.const_set "#{name_a}To#{name_b}", klass
16
16
 
17
- # An array of related classes, e.g. [Models::Category, Models::Product]
17
+ # An array of related classes, e.g. [Models::Image, Models::Product]
18
18
  klass.related_classes = [name_a, name_b].map{ |n| Models.const_get n.camelize.singularize }
19
19
 
20
20
  # Sets up paranoia, including a with_deleted scope for consistency
@@ -25,10 +25,10 @@ module Netfira::WebConnect
25
25
  end
26
26
 
27
27
  # Enables finding by origin IDs, e.g.:
28
- # CategoryToProduct.find_by_origin_ids(category: 'fruit', product: 'apple', shop: 5)
28
+ # ImageToProduct.find_by_origin_ids(image: 'apple.jpg', product: 'apple', shop: 5)
29
29
  find_by_origin_ids = proc do |**args|
30
30
 
31
- # The table of the current class, e.g. nf_categories_to_products
31
+ # The table of the current class, e.g. nf_images_to_products
32
32
  join_table = klass.arel_table
33
33
 
34
34
  # The scope we're building
@@ -44,28 +44,31 @@ module Netfira::WebConnect
44
44
  # Join each class and add where clauses
45
45
  klass.related_classes.each do |related_class|
46
46
 
47
- # The related table, e.g. nf_products
47
+ # The related table, e.g. nf_images
48
48
  related_table = related_class.arel_table
49
49
 
50
- # The argument expected to identify the relevant row of the table, e.g. :product
50
+ # The argument expected to identify the relevant row of the table, e.g. :image
51
51
  origin_id_arg = related_class.single_name.to_sym
52
52
 
53
- # The origin ID to find in the table, e.g. 'apple'
53
+ # The origin ID to find in the table, e.g. 'apple.jpg'
54
54
  origin_id = args[origin_id_arg] or raise "Missing argument `#{origin_id_arg}`"
55
55
 
56
- # The column in which to seek the origin ID, e.g. :product_id
56
+ # The column of the related table in which to seek the origin ID, e.g. :file_name
57
57
  origin_key = related_class.origin_key.to_sym
58
58
 
59
+ # The column on which to join the relation table, e.g. :image_id
60
+ join_key = :"#{related_class.single_name}_id"
61
+
59
62
  # Join the related table, e.g.:
60
- # INNER JOIN "nf_products" ON "nf_categories_to_products"."product_id" = "nf_products"."id"
61
- scope = scope.joins join_table.join(related_table).on(join_table[origin_key].eq related_table[:id]).join_sql
63
+ # INNER JOIN "nf_images" ON "nf_images_to_products"."image_id" = "nf_images"."id"
64
+ scope = scope.joins join_table.join(related_table).on(join_table[join_key].eq related_table[:id]).join_sql
62
65
 
63
66
  # Look for the origin ID, e.g.:
64
- # WHERE "nf_products"."product_id" = 'apple'
67
+ # WHERE "nf_images"."file_name" = 'apple.jpg'
65
68
  scope = scope.where related_table[origin_key].eq origin_id
66
69
 
67
70
  # Limit to the given shop, e.g.:
68
- # AND "nf_products"."shop_id" = 5
71
+ # AND "nf_images"."shop_id" = 5
69
72
  scope = scope.where related_table[:shop_id].eq shop if shop
70
73
  end
71
74
 
@@ -1,6 +1,6 @@
1
1
  module Netfira
2
2
  module WebConnect
3
- VERSION = '0.4.4'
3
+ VERSION = '0.4.5'
4
4
  PLATFORM_AND_VERSION = 'Rack/' << VERSION
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: web-connect
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Neil E. Pearson
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-08-06 00:00:00.000000000 Z
12
+ date: 2014-08-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord