unidom-category 1.2 → 1.3

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: 93576c414117bd512f8cc34e2f744098d23f4306
4
- data.tar.gz: 17bae303105dae01da620ec1f3a43d9ed7f96e9d
3
+ metadata.gz: 8f08019b4625520f38401076dfeecb7ae9554896
4
+ data.tar.gz: 6878e743ac7038c34d8129750ae784581db78c0c
5
5
  SHA512:
6
- metadata.gz: e98a45ffb2ce9c06fcdadbc17ef584de584bd21f71f856dd2bdefce3c0757691aed825f671f83f72df4ec6da0c6416ed8256a285ae508ef47b730afb47a6b6d2
7
- data.tar.gz: 15decf5e34ddb8572a3069179f82b5838cd47deca2a65e2701e0daf29cc78b4df05be965033f601446c26f7d947b68f6056f64156cfaceee85b9345ee05e70de
6
+ metadata.gz: e40165eaf0cd8a1314e9545c11de4ab734645603817af4dd171400e2352dfe30fd6117f9540c144b5eb9b6be3a48e19bd8d0191f799dd60dd01722a74a115071
7
+ data.tar.gz: 202be75deddd9cc57e4e6f3affbe50b778113154227dc8d83e8d5cb5390862bd496fc37d4031f37ebd51439b4dd3b1d7ff0aa94202dc2d66b71f3b21bf400030
data/README.md CHANGED
@@ -6,22 +6,33 @@
6
6
  Unidom (UNIfied Domain Object Model) is a series of domain model engines. The Category domain model engine includes Category and its relative models.
7
7
  Unidom (统一领域对象模型)是一系列的领域模型引擎。类别领域模型引擎包括类别及其相关的模型。
8
8
 
9
+
10
+
9
11
  ## Recent Update
10
12
  Check out the [Road Map](ROADMAP.md) to find out what's the next.
11
13
  Check out the [Change Log](CHANGELOG.md) to find out what's new.
12
14
 
15
+
16
+
13
17
  ## Usage in Gemfile
18
+
14
19
  ```ruby
15
20
  gem 'unidom-category'
16
21
  ```
17
22
 
23
+
24
+
18
25
  ## Run the Database Migration
26
+
19
27
  ```shell
20
28
  rake db:migrate
21
29
  ```
22
30
  The migration versions start with 200003.
23
31
 
32
+
33
+
24
34
  ## Call the Model
35
+
25
36
  ```ruby
26
37
  @category = Unidom::Category::Category.coded_as('x1').scheme_is(scheme).valid_at.alive.first
27
38
  Unidom::Category::Categorizing.categorize! product, into: category, at: Time.now
@@ -32,10 +43,15 @@ Unidom::Category::CategoryRollup.roll_up! child_category, into: parent_category,
32
43
  @category.categorize! @product, primary: true
33
44
  ```
34
45
 
46
+
47
+
35
48
  ## Include the Concerns
49
+
36
50
  ```ruby
37
51
  include Unidom::Category::Concerns::AsCategorized
38
52
  include Unidom::Category::Concerns::AsCategory
53
+ include Unidom::Category::Concerns::AsAncestorCategory
54
+ include Unidom::Category::Concerns::AsDescendantCategory
39
55
  ```
40
56
 
41
57
  ### As Category concern
@@ -50,3 +66,13 @@ The As Categorized concern do the following tasks for the includer automatically
50
66
  2. Define the has_many :categories macro as: ``has_many :categories, through: :categorizings, source: :category``
51
67
  3. Define the #is_categorized! method as: ``is_categorized!(into: nil, at: Time.now, primary: true)``
52
68
  4. Define the #is_categorized? method as: ``is_categorized?(into: nil, at: Time.now, primary: true)``
69
+
70
+ ### As Ancestor Category concern
71
+ The As Ancestor Category concern do the following tasks for the includer automatically:
72
+ 1. Define the has_many :descendant_category_rollups macro as: ``has_many :descendant_category_rollups, class_name: 'Unidom::Category::CategoryRollup', foreign_key: :ancestor_category_id, source: :ancestor_category``
73
+ 2. Define the has_many :descendant_categories macro as: ``has_many :descendant_categories, class_name: 'Unidom::Category::Category', through: :descendant_category_rollups``
74
+
75
+ ### As Descendant Category concern
76
+ The As Descendant Category concern do the following tasks for the includer automatically:
77
+ 1. Define the has_many :ancestor_category_rollups macro as: ``has_many :ancestor_category_rollups, class_name: 'Unidom::Category::CategoryRollup', foreign_key: :descendant_category_id, source: :descendant_category``
78
+ 2. Define the has_many :ancestor_categories macro as: ``has_many :ancestor_categories, class_name: 'Unidom::Category::Category', through: :ancestor_category_rollups``
@@ -6,18 +6,14 @@ class Unidom::Category::Category < ActiveRecord::Base
6
6
 
7
7
  include Unidom::Common::Concerns::ModelExtension
8
8
  include Unidom::Category::Concerns::AsCategory
9
+ include Unidom::Category::Concerns::AsAncestorCategory
10
+ include Unidom::Category::Concerns::AsDescendantCategory
9
11
 
10
12
  validates :name, presence: true, length: { in: 2..self.columns_hash['name'].limit }
11
13
  validates :abbreviation, allow_blank: true, length: { in: 2..self.columns_hash['abbreviation'].limit }
12
14
 
13
15
  belongs_to :scheme, class_name: 'Unidom::Category::CategoryScheme', foreign_key: :scheme_id
14
16
 
15
- has_many :ancestor_category_rollups, class_name: 'Unidom::Category::CategoryRollup', foreign_key: :descendant_category_id, source: :descendant_category
16
- has_many :ancestor_categories, class_name: 'Unidom::Category::Category', through: :ancestor_category_rollups
17
-
18
- has_many :descendant_category_rollups, class_name: 'Unidom::Category::CategoryRollup', foreign_key: :ancestor_category_id, source: :ancestor_category
19
- has_many :descendant_categories, class_name: 'Unidom::Category::Category', through: :descendant_category_rollups
20
-
21
17
  scope :scheme_is, ->(scheme) { where scheme_id: (scheme.respond_to?(:id) ? scheme.id : scheme ) }
22
18
  scope :code_length_is, ->(length) { where 'LENGTH(code) = :code_length', code_length: length }
23
19
  scope :code_starting_with, ->(prefix) { where 'code LIKE :prefix_expression', prefix_expression: prefix+'%' }
@@ -0,0 +1,15 @@
1
+ module Unidom::Category::Concerns::AsAncestorCategory
2
+
3
+ extend ActiveSupport::Concern
4
+
5
+ included do |includer|
6
+
7
+ has_many :descendant_category_rollups, class_name: 'Unidom::Category::CategoryRollup', foreign_key: :ancestor_category_id, source: :ancestor_category
8
+ has_many :descendant_categories, class_name: 'Unidom::Category::Category', through: :descendant_category_rollups
9
+
10
+ end
11
+
12
+ module ClassMethods
13
+ end
14
+
15
+ end
@@ -27,4 +27,7 @@ module Unidom::Category::Concerns::AsCategorized
27
27
 
28
28
  end
29
29
 
30
+ module ClassMethods
31
+ end
32
+
30
33
  end
@@ -26,4 +26,7 @@ module Unidom::Category::Concerns::AsCategory
26
26
 
27
27
  end
28
28
 
29
+ module ClassMethods
30
+ end
31
+
29
32
  end
@@ -0,0 +1,15 @@
1
+ module Unidom::Category::Concerns::AsDescendantCategory
2
+
3
+ extend ActiveSupport::Concern
4
+
5
+ included do |includer|
6
+
7
+ has_many :ancestor_category_rollups, class_name: 'Unidom::Category::CategoryRollup', foreign_key: :descendant_category_id, source: :descendant_category
8
+ has_many :ancestor_categories, class_name: 'Unidom::Category::Category', through: :ancestor_category_rollups
9
+
10
+ end
11
+
12
+ module ClassMethods
13
+ end
14
+
15
+ end
@@ -1,5 +1,5 @@
1
1
  module Unidom
2
2
  module Category
3
- VERSION = '1.2'.freeze
3
+ VERSION = '1.3'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unidom-category
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.2'
4
+ version: '1.3'
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-09 00:00:00.000000000 Z
11
+ date: 2016-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: unidom-common
@@ -44,8 +44,10 @@ files:
44
44
  - app/models/unidom/category/category.rb
45
45
  - app/models/unidom/category/category_rollup.rb
46
46
  - app/models/unidom/category/category_scheme.rb
47
+ - app/models/unidom/category/concerns/as_ancestor_category.rb
47
48
  - app/models/unidom/category/concerns/as_categorized.rb
48
49
  - app/models/unidom/category/concerns/as_category.rb
50
+ - app/models/unidom/category/concerns/as_descendant_category.rb
49
51
  - app/views/layouts/unidom/category/application.html.erb
50
52
  - config/routes.rb
51
53
  - db/migrate/20000301000000_create_unidom_category_schemes.rb