Unidom (UNIfied Domain Object Model) is a series of domain model engines. The Category domain model engine includes Category and its relative models. Unidom (统一领域对象模型)是一系列的领域模型引擎。类别领域模型引擎包括类别及其相关的模型。
Check out the Road Map to find out what's the next. Check out the Change Log to find out what's new.
gem 'unidom-category'
rake db:migrate
The migration versions start with 200003.
@category = Unidom::Category::Category.coded_as('x1').scheme_is(scheme).valid_at.alive.first
Unidom::Category::Categorizing.categorize! product, into: category, at: Time.now
Unidom::Category::CategoryRollup.roll_up! child_category, into: parent_category, at: Time.now
# Add the @product into the @category.
@category.categorize! @product, primary: true
include Unidom::Category::Concerns::AsCategorized
include Unidom::Category::Concerns::AsCategory
include Unidom::Category::Concerns::AsAncestorCategory
include Unidom::Category::Concerns::AsDescendantCategory
The As Category concern do the following tasks for the includer automatically:
Define the has_many :categorizings macro as: has_many :categorizings, class_name: 'Category::Categorizing'
Define the #categorize! method as: categorize!(categorized, at: Time.now, primary: true)
Define the #categorize? method as: categorize?(categorized, at: Time.now, primary: true)
The As Categorized concern do the following tasks for the includer automatically:
Define the has_many :categorizings macro as: has_many :categorizings, class_name: 'Unidom::Category::Categorizing', as: :categorized
Define the has_many :categories macro as: has_many :categories, through: :categorizings, source: :category
Define the #is_categorized! method as: is_categorized!(into: nil, at: Time.now, primary: true)
Define the #is_categorized? method as: is_categorized?(into: nil, at: Time.now, primary: true)
The As Ancestor Category concern do the following tasks for the includer automatically:
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
Define the has_many :descendant_categories macro as: has_many :descendant_categories, class_name: 'Unidom::Category::Category', through: :descendant_category_rollups
Define the #roll_up! method as: roll_up!(it, at: Time.now, primary: true)
Define the #roll_up? method as: roll_up?(it, at: Time.now, primary: true)
The As Descendant Category concern do the following tasks for the includer automatically:
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
Define the has_many :ancestor_categories macro as: has_many :ancestor_categories, class_name: 'Unidom::Category::Category', through: :ancestor_category_rollups
Define the #is_rolled_up! as: is_rolled_up!(it, at: Time.now, primary: true)
Define the #is_rolled_up? as: is_rolled_up?(it, at: Time.now, primary: true)
If you only need the app components other than models, the migrations should be neglected, and the models should not be loaded.
# config/initializers/unidom.rb
Unidom::Common.configure do |options|
options[:neglected_namespaces] = %w{
Unidom::Category
}
end
# spec/models/unidom_spec.rb
require 'unidom/category/models_rspec'
# spec/types/unidom_spec.rb
require 'unidom/category/types_rspec'
# spec/validators/unidom_spec.rb
require 'unidom/category/validators_rspec'
# spec/support/unidom_rspec_shared_examples.rb
require 'unidom/category/rspec_shared_examples'
# spec/models/unidom/category/categorizing_spec.rb
describe Unidom::Category::Categorizing, type: :model do
before :each do
end
after :each do
end
context do
model_attributes = {}
categorized = Unidom::Product::Product.create! name: 'Model X', abbreviation: 'MX', packing_norm: 'car', measurement_unit: 'car', opened_at: Time.now
tesla = Unidom::Party::Company.create! name: 'Tesla'
scheme = Unidom::Category::CategoryScheme.create! owner: tesla, name: 'eCar'
category = Unidom::Category::Category.create! scheme: scheme, name: 'Battery-powered vehicles'
it_behaves_like 'Unidom::Category::Categorizing', model_attributes, categorized, category
end
end
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。