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, SyncMessage, 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
- #unknown? ⇒ Boolean
Constructor Details
#initialize(type_object, data_object) ⇒ Message
Returns a new instance of Message.
48 49 50 51 52 53 54 55 |
# File 'lib/skyfall/firehose/message.rb', line 48 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
26 27 28 |
# File 'lib/skyfall/firehose/message.rb', line 26 def data_object @data_object end |
#did ⇒ Object (readonly) Also known as: repo
Returns the value of attribute did.
22 23 24 |
# File 'lib/skyfall/firehose/message.rb', line 22 def did @did end |
#seq ⇒ Object (readonly)
Returns the value of attribute seq.
22 23 24 |
# File 'lib/skyfall/firehose/message.rb', line 22 def seq @seq end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
22 23 24 |
# File 'lib/skyfall/firehose/message.rb', line 22 def type @type end |
#type_object ⇒ Object (readonly)
:nodoc: - consider this as semi-private API
26 27 28 |
# File 'lib/skyfall/firehose/message.rb', line 26 def type_object @type_object end |
Class Method Details
.new(data) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/skyfall/firehose/message.rb', line 28 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 '#sync' then Firehose::SyncMessage when '#tombstone' then Firehose::TombstoneMessage else Firehose::UnknownMessage end = .allocate .send(:initialize, type_object, data_object) end |
Instance Method Details
#inspect ⇒ Object
73 74 75 76 |
# File 'lib/skyfall/firehose/message.rb', line 73 def inspect vars = inspectable_variables.map { |v| "#{v}=#{instance_variable_get(v).inspect}" }.join(", ") "#<#{self.class}:0x#{object_id} #{vars}>" end |
#inspectable_variables ⇒ Object
69 70 71 |
# File 'lib/skyfall/firehose/message.rb', line 69 def inspectable_variables instance_variables - [:@type_object, :@data_object, :@blocks] end |
#operations ⇒ Object
57 58 59 |
# File 'lib/skyfall/firehose/message.rb', line 57 def operations [] end |
#time ⇒ Object
65 66 67 |
# File 'lib/skyfall/firehose/message.rb', line 65 def time @time ||= @data_object['time'] && Time.parse(@data_object['time']) end |
#unknown? ⇒ Boolean
61 62 63 |
# File 'lib/skyfall/firehose/message.rb', line 61 def unknown? self.is_a?(Firehose::UnknownMessage) end |