unidom-category 0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 87d3aff07b41cd994c3748e37eccef1ff127e6fb
4
+ data.tar.gz: b2ecbe4ced95de610b913a0682734f87cb9de5f8
5
+ SHA512:
6
+ metadata.gz: efc271cff00a910e5cb2a0450f88683d4c1e8c7120a096cedd9f67f5f973921f24c9f64b1022246ba6568642aa4d5ef204667e9f177bace4a19c196ada7cde42
7
+ data.tar.gz: 7152388673786ec788f29bacfbf195f24dc585144e54b15a104eecc6e8f507bc5430050ba317e554f1b58a3d59daee3900506bc350bf76d2f75945bb9f604e6a
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2015 Topbit Du
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # Unidom Category
2
+
3
+ Unidom (UNIfied Domain Object Model) is a series of domain model engines. The Category domain model engine includes Category and its relative models.
4
+ Unidom (统一领域对象模型)是一系列的领域模型引擎。类别领域模型引擎包括类别及其相关的模型。
5
+
6
+ ## Usage in Gemfile:
7
+ ```ruby
8
+ gem 'unidom-category'
9
+ ```
10
+
11
+ ## Run the Database Migration:
12
+ ```shell
13
+ rake db:migrate
14
+ ```
15
+
16
+ ## Call the Model:
17
+ ```ruby
18
+ Unidom::Category::Category.coded_as('x1').valid_at.alive.first
19
+ ```
data/Rakefile ADDED
@@ -0,0 +1,24 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Unidom Category'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+ load 'rails/tasks/statistics.rake'
20
+
21
+
22
+
23
+ Bundler::GemHelper.install_tasks
24
+
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,2 @@
1
+ class Unidom::Category::ApplicationController < ActionController::Base
2
+ end
@@ -0,0 +1,2 @@
1
+ module Unidom::Category::ApplicationHelper
2
+ end
@@ -0,0 +1,15 @@
1
+ # Categorizing 是分类(category)和被分类项(categorized)之间的关联关系。
2
+
3
+ class Unidom::Category::Categorizing < ::ActiveRecord::Base
4
+
5
+ self.table_name = 'unidom_categorizings'
6
+
7
+ belongs_to :category, class_name: 'Unidom::Category::Category'
8
+ belongs_to :categorized, polymorphic: true
9
+
10
+ scope :category_is, ->(category) { where category_id: (category.respond_to?(:id) ? category.id : category) }
11
+ scope :categorized_is, ->(categorized) { where categorized: categorized }
12
+
13
+ include ::Unidom::Common::Concerns::ModelExtension
14
+
15
+ end
@@ -0,0 +1,26 @@
1
+ # Category 是分类。
2
+
3
+ class Unidom::Category::Category < ActiveRecord::Base
4
+
5
+ self.table_name = 'unidom_categories'
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 }
9
+
10
+ belongs_to :scheme, class_name: 'Unidom::Category::CategoryScheme', foreign_key: :scheme_id
11
+
12
+ has_many :ancestor_category_rollups, class_name: 'Unidom::Category::CategoryRollup', foreign_key: :descendant_category_id, source: :descendant_category
13
+ has_many :ancestor_categories, class_name: 'Unidom::Category::Category', through: :ancestor_category_rollups
14
+
15
+ has_many :descendant_category_rollups, class_name: 'Unidom::Category::CategoryRollup', foreign_key: :ancestor_category_id, source: :ancestor_category
16
+ has_many :descendant_categories, class_name: 'Unidom::Category::Category', through: :descendant_category_rollups
17
+
18
+ has_many :categorizings, class_name: 'Category::Categorizing'
19
+
20
+ scope :scheme_is, ->(scheme) { where scheme_id: (scheme.respond_to?(:id) ? scheme.id : scheme ) }
21
+ scope :code_length_is, ->(length) { where 'LENGTH(code) = :code_length', code_length: length }
22
+ scope :code_starting_with, ->(prefix) { where 'code LIKE :prefix_expression', prefix_expression: prefix+'%' }
23
+
24
+ include ::Unidom::Common::Concerns::ModelExtension
25
+
26
+ end
@@ -0,0 +1,31 @@
1
+ # Category Rollup 是分类的层级关系。
2
+
3
+ class Unidom::Category::CategoryRollup < ::ActiveRecord::Base
4
+
5
+ self.table_name = 'unidom_category_rollups'
6
+
7
+ validates :distance, presence: true, numericality: { integer_only: true, greater_than: 0 }
8
+
9
+ belongs_to :ancestor_category, class_name: 'Unidom::Category::Category'
10
+ belongs_to :descendant_category, class_name: 'Unidom::Category::Category'
11
+
12
+ scope :apart, ->(distance = 1) { where distance: distance }
13
+
14
+ scope :ancestor_category_is, ->(category) { where ancestor_category_id: (category.respond_to?(:id) ? category.id : category) }
15
+ scope :descendant_category_is, ->(category) { where descendant_category_id: (category.respond_to?(:id) ? category.id : category) }
16
+
17
+ include ::Unidom::Common::Concerns::ModelExtension
18
+
19
+ after_create ->(record) {
20
+ return unless 1==record.distance
21
+ ancestor_category = record.ancestor_category_id
22
+ ancestor_category_rollups_1 = self.class.descendant_category_is(record.ancestor_category_id).alive
23
+ ancestor_category_rollups_1.each do |ancestor_category_rollup|
24
+ self.class.apart(1+ancestor_category_rollup.distance).
25
+ ancestor_category_is(ancestor_category_rollup.ancestor_category_id).
26
+ descendant_category_is(record.descendant_category_id).
27
+ first_or_create! elemental: ancestor_category_rollup.elemental, from_date: ancestor_category_rollup.from_date
28
+ end
29
+ }
30
+
31
+ end
@@ -0,0 +1,17 @@
1
+ # Category Scheme 是分类体系。
2
+ # 所有者(owner)可以是系统(System)、标准(Standard)、或者某个参与者(Party,如:Person、Shop、Company)。
3
+
4
+ class Unidom::Category::CategoryScheme < ::ActiveRecord::Base
5
+
6
+ self.table_name = 'unidom_category_schemes'
7
+
8
+ belongs_to :owner, polymorphic: true
9
+ has_many :categories, class_name: 'Unidom::Category::Category', foreign_key: :scheme_id
10
+
11
+ validates :name, presence: true, length: { in: 2..self.columns_hash['name'].limit }
12
+
13
+ scope :owned_by, ->(owner) { where owner: owner }
14
+
15
+ include ::Unidom::Common::Concerns::ModelExtension
16
+
17
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Category</title>
5
+ <%= stylesheet_link_tag "category/application", media: "all" %>
6
+ <%= javascript_include_tag "category/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ Unidom::Category::Engine.routes.draw do
2
+ end
@@ -0,0 +1,29 @@
1
+ class CreateUnidomCategorySchemes < ActiveRecord::Migration
2
+
3
+ def change
4
+
5
+ create_table :unidom_category_schemes, id: :uuid do |t|
6
+
7
+ t.references :owner, type: :uuid, null: false,
8
+ polymorphic: { null: false, default: '', limit: 200 }
9
+
10
+ t.string :name, null: false, default: '', limit: 200
11
+ t.boolean :using_code, null: false, default: false
12
+
13
+ t.text :description
14
+
15
+ t.column :state, 'char(1)', null: false, default: 'C'
16
+ t.datetime :opened_at, null: false, default: ::Time.utc(1970)
17
+ t.datetime :closed_at, null: false, default: ::Time.utc(3000)
18
+ t.boolean :defunct, null: false, default: false
19
+ t.jsonb :notation, null: false, default: {}
20
+
21
+ t.timestamps null: false
22
+
23
+ end
24
+
25
+ add_index :unidom_category_schemes, :owner_id
26
+
27
+ end
28
+
29
+ end
@@ -0,0 +1,30 @@
1
+ class CreateUnidomCategories < ActiveRecord::Migration
2
+
3
+ def change
4
+
5
+ create_table :unidom_categories, id: :uuid do |t|
6
+
7
+ t.references :scheme, type: :uuid, null: false
8
+
9
+ t.string :code, null: true, default: nil, limit: 64
10
+ t.string :name, null: false, default: '', limit: 200
11
+ t.string :abbreviation, null: true, default: nil, limit: 16
12
+
13
+ t.text :description
14
+
15
+ t.column :state, 'char(1)', null: false, default: 'C'
16
+ t.datetime :opened_at, null: false, default: ::Time.utc(1970)
17
+ t.datetime :closed_at, null: false, default: ::Time.utc(3000)
18
+ t.boolean :defunct, null: false, default: false
19
+ t.jsonb :notation, null: false, default: {}
20
+
21
+ t.timestamps null: false
22
+
23
+ end
24
+
25
+ add_index :unidom_categories, :scheme_id
26
+ add_index :unidom_categories, [ :code, :scheme_id ], unique: true
27
+
28
+ end
29
+
30
+ end
@@ -0,0 +1,28 @@
1
+ class CreateUnidomCategoryRollups < ActiveRecord::Migration
2
+
3
+ def change
4
+
5
+ create_table :unidom_category_rollups, id: :uuid do |t|
6
+
7
+ t.references :ancestor_category, type: :uuid, null: false
8
+ t.references :descendant_category, type: :uuid, null: false
9
+
10
+ t.boolean :elemental, null: false, default: false
11
+ t.integer :distance, null: false, default: 1
12
+
13
+ t.column :state, 'char(1)', null: false, default: 'C'
14
+ t.datetime :opened_at, null: false, default: ::Time.utc(1970)
15
+ t.datetime :closed_at, null: false, default: ::Time.utc(3000)
16
+ t.boolean :defunct, null: false, default: false
17
+ t.jsonb :notation, null: false, default: {}
18
+
19
+ t.timestamps null: false
20
+
21
+ end
22
+
23
+ add_index :unidom_category_rollups, :ancestor_category_id
24
+ add_index :unidom_category_rollups, :descendant_category_id
25
+
26
+ end
27
+
28
+ end
@@ -0,0 +1,28 @@
1
+ class CreateUnidomCategorizings < ActiveRecord::Migration
2
+
3
+ def change
4
+
5
+ create_table :unidom_categorizings, id: :uuid do |t|
6
+
7
+ t.references :category, type: :uuid, null: false
8
+ t.references :categorized, type: :uuid, null: false,
9
+ polymorphic: { type: :uuid, null: false }
10
+
11
+ t.boolean :elemental, null: false, default: false
12
+
13
+ t.column :state, 'char(1)', null: false, default: 'C'
14
+ t.datetime :opened_at, null: false, default: ::Time.utc(1970)
15
+ t.datetime :closed_at, null: false, default: ::Time.utc(3000)
16
+ t.boolean :defunct, null: false, default: false
17
+ t.jsonb :notation, null: false, default: {}
18
+
19
+ t.timestamps null: false
20
+
21
+ end
22
+
23
+ add_index :unidom_categorizings, :category_id
24
+ add_index :unidom_categorizings, :categorized_id
25
+
26
+ end
27
+
28
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :category do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,15 @@
1
+ module Unidom
2
+ module Category
3
+
4
+ class Engine < ::Rails::Engine
5
+
6
+ isolate_namespace ::Unidom::Category
7
+
8
+ initializer :append_migrations do |app|
9
+ config.paths['db/migrate'].expanded.each { |expanded_path| app.config.paths['db/migrate'] << expanded_path } unless app.root.to_s.match root.to_s
10
+ end
11
+
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ module Unidom
2
+ module Category
3
+ VERSION = '0.1'.freeze
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ require 'unidom/category/engine'
2
+
3
+ module Unidom
4
+ module Category
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: unidom-category
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Topbit Du
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: unidom-common
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.2'
27
+ description: Unidom (UNIfied Domain Object Model) is a series of domain model engines.
28
+ The Category domain model engine includes Category and its relative models. Unidom
29
+ (统一领域对象模型)是一系列的领域模型引擎。类别领域模型引擎包括类别及其相关的模型。
30
+ email:
31
+ - topbit.du@gmail.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - MIT-LICENSE
37
+ - README.md
38
+ - Rakefile
39
+ - app/assets/javascripts/unidom/category/application.js
40
+ - app/assets/stylesheets/unidom/category/application.css
41
+ - app/controllers/unidom/category/application_controller.rb
42
+ - app/helpers/unidom/category/application_helper.rb
43
+ - app/models/unidom/category/categorizing.rb
44
+ - app/models/unidom/category/category.rb
45
+ - app/models/unidom/category/category_rollup.rb
46
+ - app/models/unidom/category/category_scheme.rb
47
+ - app/views/layouts/unidom/category/application.html.erb
48
+ - config/routes.rb
49
+ - db/migrate/20000301000000_create_unidom_category_schemes.rb
50
+ - db/migrate/20000302000000_create_unidom_categories.rb
51
+ - db/migrate/20000303000000_create_unidom_category_rollups.rb
52
+ - db/migrate/20000304000000_create_unidom_categorizings.rb
53
+ - lib/tasks/category_tasks.rake
54
+ - lib/unidom/category.rb
55
+ - lib/unidom/category/engine.rb
56
+ - lib/unidom/category/version.rb
57
+ homepage: https://github.com/topbitdu/unidom-category
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 2.4.5.1
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: The Category domain model engine includes Category and its relative models.
81
+ test_files: []