Unidom Geo 地理领域模型引擎
Unidom (UNIfied Domain Object Model) is a series of domain model engines. The Geo domain model engine includes Town and Location 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-geo'
Run the Database Migration:
rake db:migrate
The migration versions start with 200104.
Call the Model:
Unidom::Geo::Location.valid_at.alive.first.region
active_locatings = location.locatings.valid_at.alive
location.locate! shop, by: person
Unidom::Geo::Locating.locate! location: location, located: shop
location.locate? shop, at: Time.now
Include the Concerns:
include Unidom::Geo::Concerns::AsLocated
include Unidom::Geo::Concerns::AsLocator
include Unidom::Geo::Concerns::AsRegion
As Located concern
The As Located concern do the following tasks for the includer automatically:
- Define the has_many :locatings macro as:
has_many :locatings, class_name: 'Unidom::Geo::Locating', as: :located
- Define the has_many :locations macro as:
has_many :locations, through: :locatings, source: :location
- Define the #is_located! method as:
is_located!(to: nil, by: nil, at: Time.now)
- Define the #is_located? method as:
is_located?(to: nil, at: Time.now)
As Locator concern
The As Locator concern do the following tasks for the includer automatically:
- Define the has_many :locatings macro as:
has_many :locatings, class_name: 'Unidom::Geo::Locating', as: :locator
- Define the has_many :locations macro as:
has_many :locations, through: :locatings, source: :location
- Define the #locate! method as:
locate!(it, to: nil, at: Time.now)
As Region concern
The As Region concern do the following tasks for the includer automatically:
- Define the has_many :locations macro as:
has_many :locations, class_name: 'Unidom::Geo::Location'
- Define the has_many :locatings macro as:
has_many :locatings, through: :locations, source: :locatings
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.
Unidom::Common.configure do |options|
options[:neglected_namespaces] = %w{
Unidom::Geo
}
end
RSpec examples
RSpec example manifest (run automatically)
require 'unidom/geo/models_rspec'
require 'unidom/geo/types_rspec'
require 'unidom/geo/validators_rspec'
RSpec shared examples (to be integrated)
def initialize_unidom
Unidom::Party::Person.class_eval do
include Unidom::Geo::Concerns::AsLocator
end
Unidom::Party::Shop.class_eval do
include Unidom::Geo::Concerns::AsLocated
end
Unidom::Geo::China::Region.class_eval do
include Unidom::Geo::Concerns::AsRegion
end
end
require 'unidom'
initialize_unidom
require 'unidom/geo/rspec_shared_examples'
describe Unidom::Party::Person, type: :model do
context do
model_attributes = {
name: 'Tim'
}
located_attributes = {
name: 'Walmart'
}
located = Unidom::Party::Shop.create! located_attributes
it_behaves_like 'Unidom::Geo::Concerns::AsLocator', model_attributes, located
end
end
describe Unidom::Party::Shop, type: :model do
context do
model_attributes = {
name: 'Some Shop'
}
location_attributes = {
postal_address: '#1 Some Street',
postal_code: '610000',
region_id: SecureRandom.uuid,
region_type: 'Unidom::Geo::Region::Mock'
}
location = Unidom::Geo::Location.create! location_attributes
locator_attributes = {
name: 'Tim'
}
locator = Unidom::Party::Person.create! locator_attributes
it_behaves_like 'Unidom::Geo::Concerns::AsLocated', model_attributes, location, locator
end
end
describe Unidom::Geo::China::Region, type: :model do
context do
model_attributes = {
numeric_code: '999897',
name: 'Some Region',
scheme_id: SecureRandom.uuid,
scheme_type: 'Unidom::Geo::China::Scheme::Mock'
}
it_behaves_like 'Unidom::Geo::Concerns::AsRegion', model_attributes
end
end