unidom-product 1.1 → 1.2

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: 40352144e983ce8be850d53a45988f628dc01d5a
4
- data.tar.gz: 350fb6f7c0953e770b00522617cb123cb11354cb
3
+ metadata.gz: fa1f24747854ba625570c9bebe26608694366c4e
4
+ data.tar.gz: c8a3d6e396c504d9a6297999e6f370e5e91afb87
5
5
  SHA512:
6
- metadata.gz: cf1f6c65510d97b9c4ec4c38487abde2b96b81ad9193ddfda29d55874d9fa145d861f83c82043c6ba637f9811aa4c6a9e0c1109e7362ebb837cbb90e7225731e
7
- data.tar.gz: 7dbf6a6dd3ac874dba09d5b5d175c2efa93d0a01a9d9a4c4133fc3cf02640bf7ea1a68e15970d4d8aa5f4f74466954c67d3efc85a5f5429a5d277aa5ddf1c14b
6
+ metadata.gz: 1199f8ca0da3d579897a1f56579c640b5687538f33bf0db8f185f506f4f31d0f8fe8bf78562e1ae3e8c63dcd346e0e95cb1879b4f8161e9758e2f1ec14e3c4f3
7
+ data.tar.gz: d19512da38b9e5f2f264439f1fb69bf04c23a1e214ebf76a35186f6d8f8c0741fae260c400a823f1e40980149912a876a30c9905e4d909d77365c286e3ade453
data/README.md CHANGED
@@ -65,10 +65,12 @@ include Unidom::Product::Concerns::AsTargetProductAssociating
65
65
 
66
66
  ### As Source Product Associating concern
67
67
  The As Source Product Associating concern do the following tasks for the includer automatically:
68
- 1. Define the has_many :target_product_associatings macro as: ``has_many :target_product_associatings, class_name: 'Unidom::Product::ProductAssociating', foreign_key: :source_id``
68
+ 1. Define the has_many :target_product_associatings macro as: ``has_many :target_product_associatings, class_name: 'Unidom::Product::ProductAssociating', foreign_key: :source_id``
69
69
  2. Define the has_many :target_products macro as: ``has_many :target_products, through: :target_product_associatings, source: :target``
70
+ 3. Define the #associate! method as: ``associate!(target, due_to: nil, at: Time.now, ordinal: 1)``
70
71
 
71
72
  ### As Target Product Associating concern
72
73
  The As Target Product Associating concern do the following tasks for the includer automatically:
73
- 1. Define the has_many :source_product_associatings macro as: ``has_many :source_product_associatings, class_name: 'Unidom::Product::ProductAssociating', foreign_key: :target_id``
74
+ 1. Define the has_many :source_product_associatings macro as: ``has_many :source_product_associatings, class_name: 'Unidom::Product::ProductAssociating', foreign_key: :target_id``
74
75
  2. Define the has_many :source_products macro as: ``has_many :source_products, through: :source_product_associatings, source: :source``
76
+ 3. Define the #is_associated! method as: ``is_associated!(source, due_to: nil, at: Time.now, ordinal: 1)``
@@ -7,6 +7,14 @@ module Unidom::Product::Concerns::AsSourceProductAssociating
7
7
  has_many :target_product_associatings, class_name: 'Unidom::Product::ProductAssociating', foreign_key: :source_id
8
8
  has_many :target_products, through: :target_product_associatings, source: :target
9
9
 
10
+ #def associate?(target, due_to: nil, at: Time.now)
11
+ # target_product_associatings.target_is(target).product_association_coded_as(due_to).valid_at(now: at).alive.exists?
12
+ #end
13
+
14
+ def associate!(target, due_to: nil, at: Time.now, ordinal: 1)
15
+ target_product_associatings.target_is(target).product_association_coded_as(due_to).valid_at(now: at).alive.first_or_create! ordinal: ordinal, opened_at: at
16
+ end
17
+
10
18
  end
11
19
 
12
20
  module ClassMethods
@@ -7,6 +7,14 @@ module Unidom::Product::Concerns::AsTargetProductAssociating
7
7
  has_many :source_product_associatings, class_name: 'Unidom::Product::ProductAssociating', foreign_key: :target_id
8
8
  has_many :source_products, through: :source_product_associatings, source: :source
9
9
 
10
+ #def is_associated?(source, due_to: nil, at: Time.now)
11
+ # source_product_associatings.source_is(source).product_association_coded_as(due_to).valid_at(now: at).alive.exists?
12
+ #end
13
+
14
+ def is_associated!(source, due_to: nil, at: Time.now, ordinal: 1)
15
+ source_product_associatings.source_is(source).product_association_coded_as(due_to).valid_at(now: at).alive.first_or_create! ordinal: ordinal, opened_at: at
16
+ end
17
+
10
18
  end
11
19
 
12
20
  module ClassMethods
@@ -1,5 +1,5 @@
1
1
  module Unidom
2
2
  module Product
3
- VERSION = '1.1'.freeze
3
+ VERSION = '1.2'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unidom-product
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.1'
4
+ version: '1.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Topbit Du
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-20 00:00:00.000000000 Z
11
+ date: 2016-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: unidom-common