Class: Collective::Messager::Message
- Inherits:
-
Object
- Object
- Collective::Messager::Message
- Defined in:
- lib/collective/messager.rb
Overview
Message contains the body and critical headers for Messager
Instance Attribute Summary collapse
-
#at ⇒ Object
readonly
timestamp of message generation.
-
#body ⇒ Object
readonly
JSON-compatible.
-
#from ⇒ Object
readonly
source host.
-
#id ⇒ Object
readonly
autogenerated if not supplied.
-
#reply_to_id ⇒ Object
readonly
optional.
-
#to ⇒ Object
readonly
destination host.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(data) ⇒ Message
constructor
A new instance of Message.
- #to_hash ⇒ Object
- #to_json ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(data) ⇒ Message
Returns a new instance of Message.
94 95 96 97 98 99 100 101 102 |
# File 'lib/collective/messager.rb', line 94 def initialize( data ) data = ::Collective::Messager.symbolize(data) @to = data[:to] or raise "must specify to address" @from = data[:from] or raise "must specify from address" @at = (data[:at] || Time.now).to_f @body = data[:body] @id = data[:id] || Digest::MD5.hexdigest([from,at,body].join) @reply_to_id = data[:reply_to_id] end |
Instance Attribute Details
#at ⇒ Object (readonly)
timestamp of message generation
89 90 91 |
# File 'lib/collective/messager.rb', line 89 def at @at end |
#body ⇒ Object (readonly)
JSON-compatible
90 91 92 |
# File 'lib/collective/messager.rb', line 90 def body @body end |
#from ⇒ Object (readonly)
source host
88 89 90 |
# File 'lib/collective/messager.rb', line 88 def from @from end |
#id ⇒ Object (readonly)
autogenerated if not supplied
91 92 93 |
# File 'lib/collective/messager.rb', line 91 def id @id end |
#reply_to_id ⇒ Object (readonly)
optional
92 93 94 |
# File 'lib/collective/messager.rb', line 92 def reply_to_id @reply_to_id end |
#to ⇒ Object (readonly)
destination host
87 88 89 |
# File 'lib/collective/messager.rb', line 87 def to @to end |
Class Method Details
.parse(json) ⇒ Object
118 119 120 |
# File 'lib/collective/messager.rb', line 118 def self.parse( json ) new( JSON.parse(json) ) end |
Instance Method Details
#to_hash ⇒ Object
104 105 106 107 108 |
# File 'lib/collective/messager.rb', line 104 def to_hash blob = { to: to, from: from, at: at, body: body, id: id } blob[:reply_to_id] = reply_to_id if reply_to_id blob end |
#to_json ⇒ Object
110 111 112 |
# File 'lib/collective/messager.rb', line 110 def to_json to_hash.to_json end |
#to_s ⇒ Object
114 115 116 |
# File 'lib/collective/messager.rb', line 114 def to_s to_json end |