Unidom Certificate 证书领域模型引擎

Documentation License

Gem Version Dependency Status

Unidom (UNIfied Domain Object Model) is a series of domain model engines. The Certificate domain model engine includes Identity Card and Business License models. Unidom (统一领域对象模型)是一系列的领域模型引擎。证书领域模型引擎包括身份证和营业执照的模型。

Recent Update

Check out the Road Map to find out what's the next. Check out the Change Log to find out what's new.

Usage in Gemfile

gem 'unidom-certificate'

Run the Database Migration

rake db:migrate

The migration versions start with 200102.

Call the Model

officer       = Unidom::Party::Person.create! name: 'John'
mall          = Unidom::Party::Shop.create!   name: 'WalMart'
certification = Unidom::Certificate::China::BusinessLicense.registration_number_is('123456789012345').valid_at.alive.first_or_create! name: 'WalMart', address: 'Beijing', legal_representative_name: 'Tim'
certificating = Unidom::Certificate::Certificating.certificate!(certification: certification, certificated: mall, certificator: officer, opened_at: Time.now)

Include the Concerns

include Unidom::Certificate::Concerns::AsCertificated
include Unidom::Certificate::Concerns::AsCertification

As Certificated concern

The As Certificated concern do the following tasks for the includer automatically:

  1. Define the has_many :certificatings macro as: has_many :certificatings, class_name: 'Unidom::Certificate::Certificating', as: :certificated
  2. Define the #is_certificated! method as: def is_certificated!(certification, by: nil, at: Time.now)
  3. Define the #is_certificated? method as: def is_certificated?(certification, at: Time.now)

As Certification concern

The As Certification concern do the following tasks for the includer automatically:

  1. Define the has_many :certificatings macro as: has_many :certificatings, class_name: 'Unidom::Certificate::Certificating', as: :certification
  2. Define the #certificate! method as: def certificate!(certificated, by: nil, at: Time.now)
  3. Define the #certificate? method as: def certificate?(certificated, at: Time.now)

Disable the Model & Migration

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::Certificate
  }

end

RSpec examples

# spec/models/unidom_spec.rb
require 'unidom/certificate/models_rspec'

# spec/types/unidom_spec.rb
require 'unidom/certificate/types_rspec'

# spec/validators/unidom_spec.rb
require 'unidom/certificate/validators_rspec'