web-connect 0.4.4 → 0.4.5
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/netfira/web_connect/model/relation.rb +15 -12
- data/lib/netfira/web_connect/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f63aefe6e3d4e57c35a13b8d50c498cd4f251af7
|
4
|
+
data.tar.gz: cb70abe3467ee489bf9f3360575ce59304d2a420
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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::
|
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::
|
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
|
-
#
|
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.
|
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.
|
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. :
|
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. :
|
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 "
|
61
|
-
scope = scope.joins join_table.join(related_table).on(join_table[
|
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 "
|
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 "
|
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
|
|
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
|
+
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-
|
12
|
+
date: 2014-08-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|