Unidom Shipment 装运领域模型引擎
Unidom (UNIfied Domain Object Model) is a series of domain model engines. The Shipment domain model engine includes the Shipment, Shipment Item, Shipment Package, Shipment Package Item, and Shipment Receipt model. 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-shipment'
Run the Database Migration
rake db:migrate
The migration versions start with 200210.
Call the Model
shipment = Unidom::Shipment::Shipment.valid_at.alive.first
shipment_item = Unidom::Shipment::ShipmentItem.valid_at.alive.first
shipment_items = shipment.items
inventory_item = Unidom::Inventory::GroupedInventoryItem.valid_at.alive.first
shipment_package = Unidom::Shipment::ShipmentPackage.serial_number_is('X5-20161231-1234').valid_at.alive.first
shipment_package_item = shipment_package.items.create! shipment_item: shipment_item, quantity: 10
shipment_receipt = shipment_package.receipts.create! shipped: shipment_item.shipped, store_item: inventory_item
Include the Concerns
include Unidom::Shipment::Concerns::AsShipped
As Shipped
The As Shipped concern do the following tasks for the includer automatically:
- Define the has_many :shipment_items macro as:
has_many :shipment_items, class_name: 'Unidom::Shipment::ShipmentItem', foreign_key: :shipped_id
- Define the has_many :shipment_receipts macro as:
has_many :shipment_receipts, class_name: 'Unidom::Shipment::ShipmentReceipt', foreign_key: :shipped_id
Enum codes
Conveyance enum code
Unidom::Shipment::Conveyance::customer_shipment # 客户装运
Unidom::Shipment::Conveyance::customer_return # 客户退回
Unidom::Shipment::Conveyance::purchase_shipment # 购买装运
Unidom::Shipment::Conveyance::purchase_return # 进货退回
Unidom::Shipment::Conveyance::transfer # 转运
Unidom::Shipment::Conveyance::drop_shipment # 直接装运
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::Shipment
}
end
RSpec examples
# spec/models/unidom_spec.rb
require 'unidom/shipment/models_rspec'
# spec/types/unidom_spec.rb
require 'unidom/shipment/types_rspec'
# spec/validators/unidom_spec.rb
require 'unidom/shipment/validators_rspec'