Unidom Contact China 中国联系方式领域模型引擎
Unidom (UNIfied Domain Object Model) is a series of domain model engines. The China Contact domain model engine includes China Mobile Phone Number and its relative 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-contact-china'
Run the Database Migration
rake db:migrate
The migration versions start with 2001039156.
Call the Model
phone_number = Unidom::Contact::China::MobilePhoneNumber.new phone_number: '13912345678'
phone_number.save!
Unidom::Contact::China::MobilePhoneNumber.valid_at.alive.first
# Find the first active China mobile phone number
Unidom::Contact::China::MobilePhoneNumber.phone_number_is('13912345678').first
# Find the mobile phone number per the given phone number.
Include the Concerns
include Unidom::Contact::China::Concerns::AsMobilePhoneNumberSubscriber
As Mobile Phone Number Subscriber concern
The As Mobile Phone Number Subscriber concern do the following tasks for the includer automatically:
- Define the has_many :china_mobile_phone_numbers macro as:
has_many :china_mobile_phone_numbers, through: :contact_subscriptions, source: :contact, source_type: 'Unidom::Contact::China::MobilePhoneNumber'
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 ||
[:neglected_namespaces] = %w{
Unidom::Contact::China
}
end
RSpec examples
RSpec example manifest (run automatically)
# spec/models/unidom_spec.rb
require 'unidom/contact/china/models_rspec'
# spec/types/unidom_spec.rb
require 'unidom/contact/china/types_rspec'
# spec/validators/unidom_spec.rb
require 'unidom/contact/china/validators_rspec'
RSpec shared examples (to be integrated)
# lib/unidom.rb
def initialize_unidom
Unidom::Party::Person.class_eval do
include Unidom::Contact::China::Concerns::AsMobilePhoneNumberSubscriber
end
end
# spec/rails_helper.rb
require 'unidom'
initialize_unidom
# spec/support/unidom_rspec_shared_examples.rb
require 'unidom/contact/china/rspec_shared_examples'
# spec/models/unidom/party/person_spec.rb
describe Unidom::Party::Person, type: :model do
model_attribtues = {
name: 'Tim'
}
it_behaves_like 'Unidom::Contact::China::Concerns::AsMobilePhoneNumberSubscriber', model_attribtues
end