unidom-product 1.0 → 1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eec6cc009a7832a8b54efc5d072b77c5ccce2ad0
4
- data.tar.gz: 435f58b1832e69ae946fce6a82e0d2e067c54932
3
+ metadata.gz: 40352144e983ce8be850d53a45988f628dc01d5a
4
+ data.tar.gz: 350fb6f7c0953e770b00522617cb123cb11354cb
5
5
  SHA512:
6
- metadata.gz: efed501763cd32d445c46d7fca604340373a3675a2a10937f6d6247dbd31787b53a3758a1f6bc5db45281cedeac05e4181a9f157c0e88217aa4f9fb0b61175a0
7
- data.tar.gz: 91d1ffda19db36b028a54778996bf44b5a776886508311c02997fb5665ac78988b84f8ecd1e69848685efd9935de158ad25a533b0a30de84a684c1254f16a675
6
+ metadata.gz: cf1f6c65510d97b9c4ec4c38487abde2b96b81ad9193ddfda29d55874d9fa145d861f83c82043c6ba637f9811aa4c6a9e0c1109e7362ebb837cbb90e7225731e
7
+ data.tar.gz: 7dbf6a6dd3ac874dba09d5b5d175c2efa93d0a01a9d9a4c4133fc3cf02640bf7ea1a68e15970d4d8aa5f4f74466954c67d3efc85a5f5429a5d277aa5ddf1c14b
data/README.md CHANGED
@@ -6,22 +6,34 @@
6
6
  Unidom (UNIfied Domain Object Model) is a series of domain model engines. The Product domain model engine includes Product and its relative models.
7
7
  Unidom (统一领域对象模型)是一系列的领域模型引擎。产品领域模型引擎包括产品及其相关的模型。
8
8
 
9
+
10
+
9
11
  ## Recent Update
12
+
10
13
  Check out the [Road Map](ROADMAP.md) to find out what's the next.
11
14
  Check out the [Change Log](CHANGELOG.md) to find out what's new.
12
15
 
16
+
17
+
13
18
  ## Usage in Gemfile
19
+
14
20
  ```ruby
15
21
  gem 'unidom-product'
16
22
  ```
17
23
 
24
+
25
+
18
26
  ## Run the Database Migration
27
+
19
28
  ```shell
20
29
  rake db:migrate
21
30
  ```
22
31
  The migration versions start with 200202.
23
32
 
33
+
34
+
24
35
  ## Call the Model
36
+
25
37
  ```ruby
26
38
  # Create a Product
27
39
  product = Unidom::Product::Product.create(name: 'Apple iPhone 6S Plus 64G',
@@ -41,3 +53,22 @@ Unidom::Product::ProductAssociating.associate! product_1, with: product_2, due_t
41
53
  # Find the Product Associating per the source product & the target product
42
54
  associating = Unidom::Product::ProductAssociating.source_is(product_1).target_is(product_2).first
43
55
  ```
56
+
57
+
58
+
59
+ ## Include the Concerns
60
+
61
+ ```ruby
62
+ include Unidom::Product::Concerns::AsSourceProductAssociating
63
+ include Unidom::Product::Concerns::AsTargetProductAssociating
64
+ ```
65
+
66
+ ### As Source Product Associating concern
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``
69
+ 2. Define the has_many :target_products macro as: ``has_many :target_products, through: :target_product_associatings, source: :target``
70
+
71
+ ### As Target Product Associating concern
72
+ 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
+ 2. Define the has_many :source_products macro as: ``has_many :source_products, through: :source_product_associatings, source: :source``
@@ -0,0 +1,15 @@
1
+ module Unidom::Product::Concerns::AsSourceProductAssociating
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
+ end
11
+
12
+ module ClassMethods
13
+ end
14
+
15
+ end
@@ -0,0 +1,15 @@
1
+ module Unidom::Product::Concerns::AsTargetProductAssociating
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
+ end
11
+
12
+ module ClassMethods
13
+ end
14
+
15
+ end
@@ -5,16 +5,12 @@ 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::AsSourceProductAssociating
9
+ include Unidom::Product::Concerns::AsTargetProductAssociating
8
10
 
9
11
  validates :name, presence: true, length: { in: 2..self.columns_hash['name'].limit }
10
12
  validates :abbreviation, presence: true, length: { in: 1..self.columns_hash['abbreviation'].limit }
11
13
  validates :measurement_unit, presence: true, length: { in: 1..self.columns_hash['measurement_unit'].limit }
12
14
  validates :packing_norm, presence: true, length: { in: 1..self.columns_hash['packing_norm'].limit }
13
15
 
14
- has_many :source_product_associatings, class_name: 'Unidom::Product::ProductAssociating', foreign_key: :target_id #, as: :target
15
- has_many :source_products, through: :source_product_associatings, source: :source
16
-
17
- has_many :target_product_associatings, class_name: 'Unidom::Product::ProductAssociating', foreign_key: :source_id #, as: :source
18
- has_many :target_products, through: :target_product_associatings, source: :target
19
-
20
16
  end
@@ -1,5 +1,5 @@
1
1
  module Unidom
2
2
  module Product
3
- VERSION = '1.0'.freeze
3
+ VERSION = '1.1'.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.0'
4
+ version: '1.1'
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-05 00:00:00.000000000 Z
11
+ date: 2016-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: unidom-common
@@ -40,6 +40,8 @@ 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_associating.rb
44
+ - app/models/unidom/product/concerns/as_target_product_associating.rb
43
45
  - app/models/unidom/product/product.rb
44
46
  - app/models/unidom/product/product_associating.rb
45
47
  - app/views/layouts/unidom/product/application.html.erb