unidom-product 1.3 → 1.4
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/README.md +13 -10
- data/app/models/unidom/product/concerns/as_source_product.rb +23 -0
- data/app/models/unidom/product/concerns/as_source_product_associating.rb +2 -0
- data/app/models/unidom/product/concerns/as_target_product.rb +23 -0
- data/app/models/unidom/product/concerns/as_target_product_associating.rb +2 -0
- data/app/models/unidom/product/product.rb +2 -2
- data/lib/unidom/product/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 72045ffbc53a4fddb50505e43737898afa9d8c4b
|
|
4
|
+
data.tar.gz: 9ba22176c026d61d4836c0c0f89a1fe46d3ec052
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e6b13c0ccd308e43041c1b1251b91f22deb835321f357de1a7d71ac7956cfe73ce8eab90a160ca08873d8df64fc61d8dfeb46cfb64a0583b2ce898633e94b08d
|
|
7
|
+
data.tar.gz: 7d1be11f8f4b362ebff50376af0366e4f1a6081d6b5f970ee858b75ed5ec2210ebd5be5aa598f02aa10f80b257bea594d1783a3ba4da3be89e87646459800630
|
data/README.md
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](http://opensource.org/licenses/MIT)
|
|
4
4
|
[](https://badge.fury.io/rb/unidom-product)
|
|
5
|
+
[](https://gemnasium.com/github.com/topbitdu/unidom-product)
|
|
5
6
|
|
|
6
7
|
Unidom (UNIfied Domain Object Model) is a series of domain model engines. The Product domain model engine includes Product and its relative models.
|
|
7
8
|
Unidom (统一领域对象模型)是一系列的领域模型引擎。产品领域模型引擎包括产品及其相关的模型。
|
|
@@ -59,20 +60,22 @@ associating = Unidom::Product::ProductAssociating.source_is(product_1).target_is
|
|
|
59
60
|
## Include the Concerns
|
|
60
61
|
|
|
61
62
|
```ruby
|
|
62
|
-
include Unidom::Product::Concerns::
|
|
63
|
-
include Unidom::Product::Concerns::
|
|
63
|
+
include Unidom::Product::Concerns::AsSourceProduct
|
|
64
|
+
include Unidom::Product::Concerns::AsTargetProduct
|
|
64
65
|
```
|
|
65
66
|
|
|
66
|
-
### As Source Product
|
|
67
|
-
|
|
67
|
+
### As Source Product concern
|
|
68
|
+
|
|
69
|
+
The As Source Product concern do the following tasks for the includer automatically:
|
|
68
70
|
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
|
-
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)``
|
|
71
|
+
2. Define the has_many :target_products macro as: ``has_many :target_products, through: :target_product_associatings, source: :target``
|
|
72
|
+
3. Define the #associate! method as: ``associate!(target, due_to: nil, at: Time.now, ordinal: 1)``
|
|
71
73
|
4. Define the #associate? method as: ``associate?(target, due_to: nil, at: Time.now)``
|
|
72
74
|
|
|
73
|
-
### As Target Product
|
|
74
|
-
|
|
75
|
+
### As Target Product concern
|
|
76
|
+
|
|
77
|
+
The As Target Product concern do the following tasks for the includer automatically:
|
|
75
78
|
1. Define the has_many :source_product_associatings macro as: ``has_many :source_product_associatings, class_name: 'Unidom::Product::ProductAssociating', foreign_key: :target_id``
|
|
76
|
-
2. Define the has_many :source_products macro as: ``has_many :source_products, through: :source_product_associatings, source: :source``
|
|
77
|
-
3. Define the #is_associated! method as: ``is_associated!(source, due_to: nil, at: Time.now, ordinal: 1)``
|
|
79
|
+
2. Define the has_many :source_products macro as: ``has_many :source_products, through: :source_product_associatings, source: :source``
|
|
80
|
+
3. Define the #is_associated! method as: ``is_associated!(source, due_to: nil, at: Time.now, ordinal: 1)``
|
|
78
81
|
4. Define the #is_associated? method as: ``is_associated?(source, due_to: nil, at: Time.now)``
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module Unidom::Product::Concerns::AsSourceProduct
|
|
2
|
+
|
|
3
|
+
extend ActiveSupport::Concern
|
|
4
|
+
|
|
5
|
+
included do |includer|
|
|
6
|
+
|
|
7
|
+
has_many :target_product_associatings, class_name: 'Unidom::Product::ProductAssociating', foreign_key: :source_id
|
|
8
|
+
has_many :target_products, through: :target_product_associatings, source: :target
|
|
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
|
+
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
module ClassMethods
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
end
|
|
@@ -8,10 +8,12 @@ module Unidom::Product::Concerns::AsSourceProductAssociating
|
|
|
8
8
|
has_many :target_products, through: :target_product_associatings, source: :target
|
|
9
9
|
|
|
10
10
|
def associate?(target, due_to: nil, at: Time.now)
|
|
11
|
+
warn "The Unidom::Product::Concerns::AsSourceProductAssociating#associate? method is deprecated and will be removed from unidom-product v2.0. Please use the Unidom::Product::Concerns::AsSourceProduct#associate? method instead."
|
|
11
12
|
target_product_associatings.target_is(target).product_association_coded_as(due_to).valid_at(now: at).alive.exists?
|
|
12
13
|
end
|
|
13
14
|
|
|
14
15
|
def associate!(target, due_to: nil, at: Time.now, ordinal: 1)
|
|
16
|
+
warn "The Unidom::Product::Concerns::AsSourceProductAssociating#associate! method is deprecated and will be removed from unidom-product v2.0. Please use the Unidom::Product::Concerns::AsSourceProduct#associate! method instead."
|
|
15
17
|
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
18
|
end
|
|
17
19
|
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module Unidom::Product::Concerns::AsTargetProduct
|
|
2
|
+
|
|
3
|
+
extend ActiveSupport::Concern
|
|
4
|
+
|
|
5
|
+
included do |includer|
|
|
6
|
+
|
|
7
|
+
has_many :source_product_associatings, class_name: 'Unidom::Product::ProductAssociating', foreign_key: :target_id
|
|
8
|
+
has_many :source_products, through: :source_product_associatings, source: :source
|
|
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
|
+
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
module ClassMethods
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
end
|
|
@@ -8,10 +8,12 @@ module Unidom::Product::Concerns::AsTargetProductAssociating
|
|
|
8
8
|
has_many :source_products, through: :source_product_associatings, source: :source
|
|
9
9
|
|
|
10
10
|
def is_associated?(source, due_to: nil, at: Time.now)
|
|
11
|
+
warn "The Unidom::Product::Concerns::AsTargetProductAssociating#is_associated? method is deprecated and will be removed from unidom-product v2.0. Please use the Unidom::Product::Concerns::AsTargetProduct#is_associated? method instead."
|
|
11
12
|
source_product_associatings.source_is(source).product_association_coded_as(due_to).valid_at(now: at).alive.exists?
|
|
12
13
|
end
|
|
13
14
|
|
|
14
15
|
def is_associated!(source, due_to: nil, at: Time.now, ordinal: 1)
|
|
16
|
+
warn "The Unidom::Product::Concerns::AsTargetProductAssociating#is_associated! method is deprecated and will be removed from unidom-product v2.0. Please use the Unidom::Product::Concerns::AsTargetProduct#is_associated! method instead."
|
|
15
17
|
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
18
|
end
|
|
17
19
|
|
|
@@ -5,8 +5,8 @@ class Unidom::Product::Product < ActiveRecord::Base
|
|
|
5
5
|
self.table_name = 'unidom_products'
|
|
6
6
|
|
|
7
7
|
include Unidom::Common::Concerns::ModelExtension
|
|
8
|
-
include Unidom::Product::Concerns::
|
|
9
|
-
include Unidom::Product::Concerns::
|
|
8
|
+
include Unidom::Product::Concerns::AsSourceProduct
|
|
9
|
+
include Unidom::Product::Concerns::AsTargetProduct
|
|
10
10
|
|
|
11
11
|
validates :name, presence: true, length: { in: 2..self.columns_hash['name'].limit }
|
|
12
12
|
validates :abbreviation, presence: true, length: { in: 1..self.columns_hash['abbreviation'].limit }
|
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.
|
|
4
|
+
version: '1.4'
|
|
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-10-
|
|
11
|
+
date: 2016-10-08 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: unidom-common
|
|
@@ -40,7 +40,9 @@ files:
|
|
|
40
40
|
- app/assets/stylesheets/unidom/product/application.css
|
|
41
41
|
- app/controllers/unidom/product/application_controller.rb
|
|
42
42
|
- app/helpers/unidom/product/application_helper.rb
|
|
43
|
+
- app/models/unidom/product/concerns/as_source_product.rb
|
|
43
44
|
- app/models/unidom/product/concerns/as_source_product_associating.rb
|
|
45
|
+
- app/models/unidom/product/concerns/as_target_product.rb
|
|
44
46
|
- app/models/unidom/product/concerns/as_target_product_associating.rb
|
|
45
47
|
- app/models/unidom/product/product.rb
|
|
46
48
|
- app/models/unidom/product/product_associating.rb
|