unidom-category 0.1 → 0.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: 87d3aff07b41cd994c3748e37eccef1ff127e6fb
4
- data.tar.gz: b2ecbe4ced95de610b913a0682734f87cb9de5f8
3
+ metadata.gz: 415e223454b3de13b0237296dfdc26a2fcdf8b17
4
+ data.tar.gz: 5d21d94f0d68d7355c75dcbdf98dfc160155dda1
5
5
  SHA512:
6
- metadata.gz: efc271cff00a910e5cb2a0450f88683d4c1e8c7120a096cedd9f67f5f973921f24c9f64b1022246ba6568642aa4d5ef204667e9f177bace4a19c196ada7cde42
7
- data.tar.gz: 7152388673786ec788f29bacfbf195f24dc585144e54b15a104eecc6e8f507bc5430050ba317e554f1b58a3d59daee3900506bc350bf76d2f75945bb9f604e6a
6
+ metadata.gz: 8682be757753ef3bee1d4f49f0b1885cab18a05b2d4bc939f24a279877b75c5916fb2ec2a7aae7e92ff463afe9dcffc4caa0f07f14ce275b89133995aefb2b03
7
+ data.tar.gz: 16c38d3e63fc98883d73187f6abdb37aa87ea5cb47df17fe767751f6daa38fc0ba8e93d0404dcf95ca5a32cf321442ef88b74b564123222f6388db54965aa0a2
data/README.md CHANGED
@@ -1,19 +1,28 @@
1
- # Unidom Category
1
+ # Unidom Category 类别领域模型引擎
2
+
3
+ [![License](https://img.shields.io/badge/license-MIT-green.svg)](http://opensource.org/licenses/MIT)
4
+ [![Gem Version](https://badge.fury.io/rb/unidom-category.svg)](https://badge.fury.io/rb/unidom-category)
2
5
 
3
6
  Unidom (UNIfied Domain Object Model) is a series of domain model engines. The Category domain model engine includes Category and its relative models.
4
7
  Unidom (统一领域对象模型)是一系列的领域模型引擎。类别领域模型引擎包括类别及其相关的模型。
5
8
 
6
- ## Usage in Gemfile:
9
+ ## Recent Update
10
+ Check out the [Road Map](ROADMAP.md) to find out what's the next.
11
+ Check out the [Change Log](CHANGELOG.md) to find out what's new.
12
+
13
+ ## Usage in Gemfile
7
14
  ```ruby
8
15
  gem 'unidom-category'
9
16
  ```
10
17
 
11
- ## Run the Database Migration:
18
+ ## Run the Database Migration
12
19
  ```shell
13
20
  rake db:migrate
14
21
  ```
22
+ The migration versions start with 200003.
15
23
 
16
- ## Call the Model:
24
+ ## Call the Model
17
25
  ```ruby
18
- Unidom::Category::Category.coded_as('x1').valid_at.alive.first
26
+ Unidom::Category::Category.coded_as('x1').scheme_is(scheme).valid_at.alive.first
27
+ Unidom::Category::Categorizing.categorize!(category, product)
19
28
  ```
@@ -10,4 +10,4 @@
10
10
  // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
11
  // about supported directives.
12
12
  //
13
- //= require_tree .
13
+ //= require_self
@@ -10,6 +10,5 @@
10
10
  * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
11
  * file per style scope.
12
12
  *
13
- *= require_tree .
14
13
  *= require_self
15
14
  */
@@ -1,15 +1,19 @@
1
1
  # Categorizing 是分类(category)和被分类项(categorized)之间的关联关系。
2
2
 
3
- class Unidom::Category::Categorizing < ::ActiveRecord::Base
3
+ class Unidom::Category::Categorizing < ActiveRecord::Base
4
4
 
5
5
  self.table_name = 'unidom_categorizings'
6
6
 
7
+ include Unidom::Common::Concerns::ModelExtension
8
+
7
9
  belongs_to :category, class_name: 'Unidom::Category::Category'
8
10
  belongs_to :categorized, polymorphic: true
9
11
 
10
- scope :category_is, ->(category) { where category_id: (category.respond_to?(:id) ? category.id : category) }
11
- scope :categorized_is, ->(categorized) { where categorized: categorized }
12
+ scope :category_is, ->(category) { where category_id: to_id(category) }
13
+ scope :categorized_is, ->(categorized) { where categorized: categorized }
12
14
 
13
- include ::Unidom::Common::Concerns::ModelExtension
15
+ def self.categorize!(category, categorized, opened_at = Time.now)
16
+ self.categorized_is(categorized).category_is(category).valid_at.alive.first_or_create! elemental: true, opened_at: opened_at
17
+ end
14
18
 
15
19
  end
@@ -4,8 +4,10 @@ class Unidom::Category::Category < ActiveRecord::Base
4
4
 
5
5
  self.table_name = 'unidom_categories'
6
6
 
7
- validates :name, presence: true, length: { in: 2..self.columns_hash['name'].length }
8
- validates :abbreviation, allow_blank: true, length: { in: 2..self.columns_hash['abbreviation'].length }
7
+ include Unidom::Common::Concerns::ModelExtension
8
+
9
+ validates :name, presence: true, length: { in: 2..self.columns_hash['name'].limit }
10
+ validates :abbreviation, allow_blank: true, length: { in: 2..self.columns_hash['abbreviation'].limit }
9
11
 
10
12
  belongs_to :scheme, class_name: 'Unidom::Category::CategoryScheme', foreign_key: :scheme_id
11
13
 
@@ -21,6 +23,4 @@ class Unidom::Category::Category < ActiveRecord::Base
21
23
  scope :code_length_is, ->(length) { where 'LENGTH(code) = :code_length', code_length: length }
22
24
  scope :code_starting_with, ->(prefix) { where 'code LIKE :prefix_expression', prefix_expression: prefix+'%' }
23
25
 
24
- include ::Unidom::Common::Concerns::ModelExtension
25
-
26
26
  end
@@ -1,9 +1,11 @@
1
1
  # Category Rollup 是分类的层级关系。
2
2
 
3
- class Unidom::Category::CategoryRollup < ::ActiveRecord::Base
3
+ class Unidom::Category::CategoryRollup < ActiveRecord::Base
4
4
 
5
5
  self.table_name = 'unidom_category_rollups'
6
6
 
7
+ include Unidom::Common::Concerns::ModelExtension
8
+
7
9
  validates :distance, presence: true, numericality: { integer_only: true, greater_than: 0 }
8
10
 
9
11
  belongs_to :ancestor_category, class_name: 'Unidom::Category::Category'
@@ -14,8 +16,6 @@ class Unidom::Category::CategoryRollup < ::ActiveRecord::Base
14
16
  scope :ancestor_category_is, ->(category) { where ancestor_category_id: (category.respond_to?(:id) ? category.id : category) }
15
17
  scope :descendant_category_is, ->(category) { where descendant_category_id: (category.respond_to?(:id) ? category.id : category) }
16
18
 
17
- include ::Unidom::Common::Concerns::ModelExtension
18
-
19
19
  after_create ->(record) {
20
20
  return unless 1==record.distance
21
21
  ancestor_category = record.ancestor_category_id
@@ -28,4 +28,8 @@ class Unidom::Category::CategoryRollup < ::ActiveRecord::Base
28
28
  end
29
29
  }
30
30
 
31
+ def self.roll_up!(ancestor_category, descendant_category, opened_at = Time.now)
32
+ self.descendant_category_is(descendant_category).ancestor_category_is(ancestor_category).valid_at.alive.first_or_create! opened_at: opened_at
33
+ end
34
+
31
35
  end
@@ -1,10 +1,12 @@
1
1
  # Category Scheme 是分类体系。
2
2
  # 所有者(owner)可以是系统(System)、标准(Standard)、或者某个参与者(Party,如:Person、Shop、Company)。
3
3
 
4
- class Unidom::Category::CategoryScheme < ::ActiveRecord::Base
4
+ class Unidom::Category::CategoryScheme < ActiveRecord::Base
5
5
 
6
6
  self.table_name = 'unidom_category_schemes'
7
7
 
8
+ include Unidom::Common::Concerns::ModelExtension
9
+
8
10
  belongs_to :owner, polymorphic: true
9
11
  has_many :categories, class_name: 'Unidom::Category::Category', foreign_key: :scheme_id
10
12
 
@@ -12,6 +14,4 @@ class Unidom::Category::CategoryScheme < ::ActiveRecord::Base
12
14
 
13
15
  scope :owned_by, ->(owner) { where owner: owner }
14
16
 
15
- include ::Unidom::Common::Concerns::ModelExtension
16
-
17
17
  end
@@ -0,0 +1,12 @@
1
+ module Unidom::Category::Concerns::AsCategorized
2
+
3
+ extend ActiveSupport::Concern
4
+
5
+ self.included do |includer|
6
+
7
+ has_many :categorizings, class_name: 'Unidom::Category::Categorizing', as: :categorized
8
+ has_many :categories, through: :categorizings, source: :category
9
+
10
+ end
11
+
12
+ end
@@ -1,14 +1,15 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
3
  <head>
4
- <title>Category</title>
5
- <%= stylesheet_link_tag "category/application", media: "all" %>
6
- <%= javascript_include_tag "category/application" %>
4
+ <title>Unidom Category</title>
5
+ <%= stylesheet_link_tag 'category/application', media: 'all' %>
7
6
  <%= csrf_meta_tags %>
8
7
  </head>
9
8
  <body>
10
9
 
11
10
  <%= yield %>
12
11
 
12
+ <%= javascript_include_tag 'category/application' %>
13
+
13
14
  </body>
14
15
  </html>
@@ -1,5 +1,5 @@
1
1
  module Unidom
2
2
  module Category
3
- VERSION = '0.1'.freeze
3
+ VERSION = '0.2'.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: '0.1'
4
+ version: '0.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-01-22 00:00:00.000000000 Z
11
+ date: 2016-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: unidom-common
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.2'
19
+ version: '0.9'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.2'
26
+ version: '0.9'
27
27
  description: Unidom (UNIfied Domain Object Model) is a series of domain model engines.
28
28
  The Category domain model engine includes Category and its relative models. Unidom
29
29
  (统一领域对象模型)是一系列的领域模型引擎。类别领域模型引擎包括类别及其相关的模型。
@@ -44,6 +44,7 @@ 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_categorized.rb
47
48
  - app/views/layouts/unidom/category/application.html.erb
48
49
  - config/routes.rb
49
50
  - db/migrate/20000301000000_create_unidom_category_schemes.rb
@@ -74,8 +75,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
75
  version: '0'
75
76
  requirements: []
76
77
  rubyforge_project:
77
- rubygems_version: 2.4.5.1
78
+ rubygems_version: 2.6.4
78
79
  signing_key:
79
80
  specification_version: 4
80
- summary: The Category domain model engine includes Category and its relative models.
81
+ summary: Unidom Category Domain Model Engine 类别领域模型引擎
81
82
  test_files: []