Class: Skyfall::Firehose::Message
- Inherits:
-
Object
- Object
- Skyfall::Firehose::Message
- Defined in:
- lib/skyfall/firehose/message.rb
Direct Known Subclasses
AccountMessage, CommitMessage, HandleMessage, IdentityMessage, InfoMessage, TombstoneMessage, UnknownMessage
Instance Attribute Summary collapse
-
#data_object ⇒ Object
readonly
:nodoc: - consider this as semi-private API.
-
#did ⇒ Object
(also: #repo)
readonly
Returns the value of attribute did.
-
#seq ⇒ Object
readonly
Returns the value of attribute seq.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#type_object ⇒ Object
readonly
:nodoc: - consider this as semi-private API.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(type_object, data_object) ⇒ Message
constructor
A new instance of Message.
- #inspect ⇒ Object
- #inspectable_variables ⇒ Object
- #operations ⇒ Object
- #time ⇒ Object
Constructor Details
#initialize(type_object, data_object) ⇒ Message
Returns a new instance of Message.
46 47 48 49 50 51 52 53 |
# File 'lib/skyfall/firehose/message.rb', line 46 def initialize(type_object, data_object) @type_object = type_object @data_object = data_object @type = @type_object['t'][1..-1].to_sym @did = @data_object['repo'] || @data_object['did'] @seq = @data_object['seq'] end |
Instance Attribute Details
#data_object ⇒ Object (readonly)
:nodoc: - consider this as semi-private API
25 26 27 |
# File 'lib/skyfall/firehose/message.rb', line 25 def data_object @data_object end |
#did ⇒ Object (readonly) Also known as: repo
Returns the value of attribute did.
21 22 23 |
# File 'lib/skyfall/firehose/message.rb', line 21 def did @did end |
#seq ⇒ Object (readonly)
Returns the value of attribute seq.
21 22 23 |
# File 'lib/skyfall/firehose/message.rb', line 21 def seq @seq end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
21 22 23 |
# File 'lib/skyfall/firehose/message.rb', line 21 def type @type end |
#type_object ⇒ Object (readonly)
:nodoc: - consider this as semi-private API
25 26 27 |
# File 'lib/skyfall/firehose/message.rb', line 25 def type_object @type_object end |
Class Method Details
.new(data) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/skyfall/firehose/message.rb', line 27 def self.new(data) type_object, data_object = decode_cbor_objects(data) = case type_object['t'] when '#account' then Firehose::AccountMessage when '#commit' then Firehose::CommitMessage when '#handle' then Firehose::HandleMessage when '#identity' then Firehose::IdentityMessage when '#info' then Firehose::InfoMessage when '#labels' then Firehose::LabelsMessage when '#tombstone' then Firehose::TombstoneMessage else Firehose::UnknownMessage end = .allocate .send(:initialize, type_object, data_object) end |
Instance Method Details
#inspect ⇒ Object
67 68 69 70 |
# File 'lib/skyfall/firehose/message.rb', line 67 def inspect vars = inspectable_variables.map { |v| "#{v}=#{instance_variable_get(v).inspect}" }.join(", ") "#<#{self.class}:0x#{object_id} #{vars}>" end |
#inspectable_variables ⇒ Object
63 64 65 |
# File 'lib/skyfall/firehose/message.rb', line 63 def inspectable_variables instance_variables - [:@type_object, :@data_object, :@blocks] end |
#operations ⇒ Object
55 56 57 |
# File 'lib/skyfall/firehose/message.rb', line 55 def operations [] end |
#time ⇒ Object
59 60 61 |
# File 'lib/skyfall/firehose/message.rb', line 59 def time @time ||= @data_object['time'] && Time.parse(@data_object['time']) end |