Class: Marconi::Envelope
- Inherits:
-
Object
- Object
- Marconi::Envelope
- Defined in:
- lib/marconi/envelope.rb
Instance Attribute Summary collapse
-
#topic ⇒ Object
Returns the value of attribute topic.
Class Method Summary collapse
Instance Method Summary collapse
- #contents ⇒ Object
- #create(model) ⇒ Object
- #destroy(model) ⇒ Object
-
#initialize(options = {}, &block) ⇒ Envelope
constructor
A new instance of Envelope.
- #messages ⇒ Object
- #override(old_guid, model) ⇒ Object
- #to_s ⇒ Object
- #update(model) ⇒ Object
Constructor Details
#initialize(options = {}, &block) ⇒ Envelope
Returns a new instance of Envelope.
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/marconi/envelope.rb', line 20 def initialize( = {}, &block) if xml = [:xml] hash = SmartXML.parse(xml) @topic = hash[:headers][:topic] hash[:payload].each do |hsh| << { :meta => hsh[:meta], :data => HashWithIndifferentAccess.new(hsh[:data]) } end else @timestamp = [:timestamp] || Time.now @topic = [:topic] block.call(self) if block_given? end end |
Instance Attribute Details
#topic ⇒ Object
Returns the value of attribute topic.
9 10 11 |
# File 'lib/marconi/envelope.rb', line 9 def topic @topic end |
Class Method Details
Instance Method Details
#contents ⇒ Object
38 39 40 |
# File 'lib/marconi/envelope.rb', line 38 def contents { :headers => headers, :payload => } end |
#create(model) ⇒ Object
42 43 44 |
# File 'lib/marconi/envelope.rb', line 42 def create(model) (model, :create) end |
#destroy(model) ⇒ Object
50 51 52 |
# File 'lib/marconi/envelope.rb', line 50 def destroy(model) (model, :destroy) end |
#messages ⇒ Object
34 35 36 |
# File 'lib/marconi/envelope.rb', line 34 def @messages ||= [] end |
#override(old_guid, model) ⇒ Object
54 55 56 |
# File 'lib/marconi/envelope.rb', line 54 def override(old_guid, model) (model, :override, old_guid) end |
#to_s ⇒ Object
58 59 60 |
# File 'lib/marconi/envelope.rb', line 58 def to_s contents.to_xml end |
#update(model) ⇒ Object
46 47 48 |
# File 'lib/marconi/envelope.rb', line 46 def update(model) (model, :update) end |