Class: Stock::Director
- Inherits:
-
Object
- Object
- Stock::Director
- Defined in:
- lib/porp/stock/director.rb
Overview
The Director class mediates the complex interactions between the various stock related classes, in particular the Holding class, which represents the actual stock, and the Entity, Holder, and Status classes, which between them represent the three orthogonal concepts of what that stock is, where does it belong, and what state is it in.
The model of stock in Orp is of holdings of stock moving though various states and holders, with each combination of entity, holder, and status being represented by a Holding. Thus when the holder or status of a holding of stock changes, the stock moves from one holding to another by way of a Movement. Stock enters and leaves the system of stock holdings by way of movements from and to non-stock MovementTargets.
The model is sharded based on entity: any given stock entity requires at least one holder in which holdings can exist, and at least one state of 'in stock' e.g. the state stock is in when it exists in your retail outlet and available for purchase by your customers. However, the precise model is dependent on the requirements of a particular retail operation and their application for any given entity or collection of entities.
It therefore falls to the Director class to take the model specified by user configuration and apply it on a product group, stock entity, and default basis as appropriate.
Class Method Summary (collapse)
-
+ (Object) build_from_options(description, opts)
Build a stock entity and dependencies from passed options.
Class Method Details
+ (Object) build_from_options(description, opts)
Build a stock entity and dependencies from passed options
to create holdings for
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/porp/stock/director.rb', line 43 def self.(description, opts) # Ensure holders and statuses exist ensure_holders(opts[:holders]) ensure_statuses(opts[:statuses]) # Create the entity entity = Entity.create(description: description) # Create holdings for every permutation of entity, holder, and status holding_permutations(entity, opts[:holders], opts[:statuses]) do |entity, holder, status| Holding.create(entity: entity, holder: holder, status: status) end # Return the entity entity end |