Unidom Accession 就职领域模型引擎
Unidom (UNIfied Domain Object Model) is a series of domain model engines. The Accession domain model engine includes Post Fullfillment 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-accession'
Run the Database Migration
rake db:migrate
The migration versions start with 200405.
Call the Model
post_fulfillment = Unidom::Accession::PostFulfillment.valid_at.alive.first
post_fulfillment = Unidom::Accession::PostFulfillment.fulfill! fulfiller: fulfiller, fulfilled: post, opened_at: Time.now
# or like the following source codes, which opened_at is optional
post_fulfillment = Unidom::Accession::PostFulfillment.fulfill! fulfiller: fulfiller, fulfilled: post
part_time_fulfillments = Unidom::Accession::PostFulfillment.part_time.temporary(false) # all part time & permanent post fulfillments
temporary_fulfillments = Unidom::Accession::PostFulfillment.part_time(false).temporary # all full time & temporary post fulfillments
Include the Concern
include Unidom::Accession::Concerns::AsPostFulfilled
include Unidom::Accession::Concerns::AsPostFulfiller
As Post Fulfilled concern
The As Post Fulfilled concern do the following tasks for the includer automatically:
-
Define the has_many :post_fulfillments macro as:
has_many :post_fulfillments, class_name: 'Unidom::Accession::PostFulfillment', as: :fulfilled
-
Define the has_many :fulfiller_people macro as:
has_many :fulfiller_people, through: :post_fulfillments, source: :fulfiller, source_type: 'Unidom::Party::Person'
-
Define the #is_fulfilled_as_post! method as:
def is_fulfilled_as_post!(by: nil, at: Time.now)
-
Define the #is_fulfilled_as_post? method as:
def is_fulfilled_as_post?(by: nil, at: Time.now)
As Post Fulfiller concern
The As Post Fulfiller concern do the following tasks for the includer automatically:
-
Define the has_many :post_fulfillments macro as:
has_many :post_fulfillments, class_name: 'Unidom::Accession::PostFulfillment', as: :fulfiller
-
Define the has_many :fulfilled_posts macro as:
has_many :fulfilled_posts, through: :post_fulfillments, source: :fulfilled, source_type: 'Unidom::Position::Post'
-
Define the #fulfill_post! method as:
def fulfill_post!(post, at: Time.now)
-
Define the #fulfill_post? method as:
def fulfill_post?(post, 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::Accession
}
end
RSpec examples
RSpec example manifest (run automatically)
# spec/models/unidom_spec.rb
require 'unidom/accession/models_rspec'
# spec/types/unidom_spec.rb
require 'unidom/accession/types_rspec'
# spec/validators/unidom_spec.rb
require 'unidom/accession/validators_rspec'
RSpec shared examples (to be integrated)
# lib/unidom.rb
def initialize_unidom
Unidom::Party::Person.class_eval do
include Unidom::Accession::Concerns::AsPostFulfiller
end
Unidom::Position::Post.class_eval do
include Unidom::Accession::Concerns::AsPostFulfilled
end
end
# spec/rails_helper.rb
require 'unidom'
initialize_unidom
# spec/support/unidom_rspec_shared_examples.rb
require 'unidom/accession/rspec_shared_examples'
# spec/models/unidom/accession/post_fulfillment_spec.rb
describe Unidom::Accession::PostFulfillment, type: :model do
before :each do
end
after :each do
end
context do
model_attributes = {}
post_fulfiller = Unidom::Party::Person.create! name: 'Tim'
company = Unidom::Party::Company.create! name: 'Space X'
occupation = Unidom::Position::Occupation.first_or_create! scheme_id: SecureRandom.uuid, scheme_type: 'Unidom::Accession::Scheme::Mock', code: 'OC-00', name: 'Some Occupation'
position = occupation.positions.first_or_create! organization: company, name: occupation.name
post_fulfilled = position.posts.first_or_create! organization: company, name: position.name
it_behaves_like 'Unidom::Accession::PostFulfillment', model_attributes, post_fulfilled, post_fulfiller
end
end
# spec/models/unidom/party/person_spec.rb
describe Unidom::Party::Person do
model_attribtues = {
name: 'Tim'
}
post_attribtues = {
name: 'HR Manager',
organization_id: SecureRandom.uuid,
organization_type: 'Unidom::Position::Organization::Mock',
position_id: SecureRandom.uuid
}
post = Unidom::Position::Post.create! post_attributes
it_behaves_like 'Unidom::Accession::Concerns::AsPostFulfiller', model_attribtues, post
end
# spec/models/unidom/position/post_spec.rb
describe Unidom::Position::Post do
model_attribtues = {
name: 'HR Manager',
organization_id: SecureRandom.uuid,
organization_type: 'Unidom::Position::Organization::Mock',
position_id: SecureRandom.uuid
}
post_fulfiller = Unidom::Party::Person.create! name: 'Tim'
it_behaves_like 'Unidom::Accession::Concerns::AsPostFulfilled', model_attribtues, post_fulfiller
end