Class: Euston::EventHeaders
- Inherits:
-
Object
- Object
- Euston::EventHeaders
- Defined in:
- lib/euston/event_headers.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#source_message ⇒ Object
readonly
Returns the value of attribute source_message.
-
#source_message_type ⇒ Object
readonly
Returns the value of attribute source_message_type.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(id, type, version, timestamp = Time.now, source_message = nil, source_message_type = nil) ⇒ EventHeaders
constructor
A new instance of EventHeaders.
- #to_hash ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(id, type, version, timestamp = Time.now, source_message = nil, source_message_type = nil) ⇒ EventHeaders
Returns a new instance of EventHeaders.
5 6 7 8 9 10 11 12 |
# File 'lib/euston/event_headers.rb', line 5 def initialize id, type, version, = Time.now, = nil, = nil @id = id @type = type @version = version @timestamp = Time.at().utc @source_message = @source_message_type = end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/euston/event_headers.rb', line 3 def id @id end |
#source_message ⇒ Object (readonly)
Returns the value of attribute source_message.
3 4 5 |
# File 'lib/euston/event_headers.rb', line 3 def @source_message end |
#source_message_type ⇒ Object (readonly)
Returns the value of attribute source_message_type.
3 4 5 |
# File 'lib/euston/event_headers.rb', line 3 def @source_message_type end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
3 4 5 |
# File 'lib/euston/event_headers.rb', line 3 def @timestamp end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
3 4 5 |
# File 'lib/euston/event_headers.rb', line 3 def type @type end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
3 4 5 |
# File 'lib/euston/event_headers.rb', line 3 def version @version end |
Class Method Details
.from_hash(hash) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/euston/event_headers.rb', line 22 def self.from_hash hash if hash.has_key? :command = hash[:command] = :command elsif hash.has_key? :event_subscription = hash[:event_subscription] = :event_subscription end self.new hash[:id], hash[:type].to_sym, hash[:version], hash[:timestamp], , end |
Instance Method Details
#to_hash ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/euston/event_headers.rb', line 14 def to_hash ((@source_message_type && @source_message) ? Hash[@source_message_type, @source_message] : {}) .merge :id => id, :type => type, :version => version, :timestamp => end |
#to_s ⇒ Object
34 35 36 |
# File 'lib/euston/event_headers.rb', line 34 def to_s "#{id} #{type} (v#{version})" end |