Class: Serf::ParcelFactory
- Inherits:
 - 
      Object
      
        
- Object
 - Serf::ParcelFactory
 
 
- Defined in:
 - lib/serf/parcel_factory.rb
 
Overview
Creates Parcels as Hashie::Mash objects with headers and messages.
The headers this factory sets are:
- 
kind
 - 
uuid
 - 
parent_uuid
 - 
origin_uuid
 
The message field:
- 
message
 
The UUID fields are created using the uuidable processed from the parent parcel.
Instance Attribute Summary collapse
- 
  
    
      #mash_class  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute mash_class.
 - 
  
    
      #uuidable  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute uuidable.
 
Instance Method Summary collapse
- #create(*args) ⇒ Object
 - 
  
    
      #initialize(*args)  ⇒ ParcelFactory 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of ParcelFactory.
 
Constructor Details
#initialize(*args) ⇒ ParcelFactory
Returns a new instance of ParcelFactory.
      27 28 29 30 31 32  | 
    
      # File 'lib/serf/parcel_factory.rb', line 27 def initialize(*args) opts = Optser. args @mash_class = opts.get :mash_class, Hashie::Mash @uuidable = opts.get(:uuidable) { Serf::Util::Uuidable.new } end  | 
  
Instance Attribute Details
#mash_class ⇒ Object (readonly)
Returns the value of attribute mash_class.
      24 25 26  | 
    
      # File 'lib/serf/parcel_factory.rb', line 24 def mash_class @mash_class end  | 
  
#uuidable ⇒ Object (readonly)
Returns the value of attribute uuidable.
      25 26 27  | 
    
      # File 'lib/serf/parcel_factory.rb', line 25 def uuidable @uuidable end  | 
  
Instance Method Details
#create(*args) ⇒ Object
      34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51  | 
    
      # File 'lib/serf/parcel_factory.rb', line 34 def create(*args) opts = Optser. args # Get parameters kind = opts.get :kind parent = opts.get :parent, {} headers = opts.get :headers, {} = opts.get :message, {} # Create a new parcel, with the header fields as base of object. # Merge in the new UUIDs, overwriting anything set in headers. # Merge in the kind and message, overwriting anything already set. parcel = mash_class.new(headers) parcel.merge! uuidable.create_uuids(parent) parcel.merge! kind: kind, message: return parcel end  |