Unidom Common 常用领域模型引擎
Unidom (UNIfied Domain Object Model) is a series of domain model engines. The Common domain model engine includes the common models. Unidom (统一领域对象模型)是一系列的领域模型引擎。常用领域模型引擎包括一些常用的模型。
Usage in Gemfile
gem 'unidom-common'
Run the Database Migration
rake db:migrate
The migration enabled the PostgreSQL uuid-ossp extension.
Include Concern in Models
include Unidom::Common::Concerns::ModelExtension
Auto Generated Methods
class Project < ActiveRecord::Base
include Unidom::Common::Concerns::ModelExtension
validates :name, presence: true, length: { in: 2..200 }
belongs_to :customer
belongs_to :team
# other fields: code, description
end
Project.coded_as('JIRA').valid_at(Time.now).alive(true) # Same as Project.coded_as('JIRA').valid_at.alive
team.projects.valid_during('2015-01-01'..'2015-12-31').dead
Project.included_by([ id_1, id_2 ]).excluded_by id_3
No-SQL Columns
class Project < ActiveRecord::Base
include Unidom::Common::Concerns::ModelExtension
validates :creator_comment, allow_blank: true, length: { in: 2..200 }
validates :last_updater_comment, allow_blank: true, length: { in: 2..200 }
notation_column :creator_comment, :last_updater_comment
end
project = Project.new
project.creator_comment = 'My first project.' # Stored in project.notation['columns']['creator_comment']
project.valid? # true
ActiveRecord Migration Naming Convention
Domain Models (200YMMDDHHMMSS)
- unidom-common: 200001DDHHMMSS
- unidom-visitor: 200002DDHHMMSS
- unidom-category: 200003DDHHMMSS
- unidom-authorization: 200004DDHHMMSS
- unidom-accounting: 200005DDHHMMSS
- unidom-standard: 200006DDHHMMSS
- unidom-party: 200101DDHHMMSS
- unidom-certificate: 200102DDHHMMSS
- unidom-contact: 200103DDHHMMSS
- unidom-geo: 200104DDHHMMSS
- unidom-property: 200105DDHHMMSS
- unidom-article_number: 200201DDHHMMSS
- unidom-product: 200202DDHHMMSS
- unidom-price: 200203DDHHMMSS
- unidom-commodity: 200204DDHHMMSS
- unidom-shopping: 200205DDHHMMSS
- unidom-order: 200206DDHHMMSS
- unidom-promotion: 200207DDHHMMSS
- unidom-payment: 200208DDHHMMSS
Country Extensions (200YMM9NNNMMSS)
The YMM part should be identical to the relative part of the Domain Models. The NNN is the numeric code of ISO 3166-1. The numeric code of China is 156.
- unidom-certificate-china: 2001029156MMSS
- unidom-contact-china: 2001039156MMSS
- unidom-geo-china: 2001049156MMSS