Class: Skyfall::Firehose::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/skyfall/firehose/message.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_objectObject (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

#didObject (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

#seqObject (readonly)

Returns the value of attribute seq.



21
22
23
# File 'lib/skyfall/firehose/message.rb', line 21

def seq
  @seq
end

#typeObject (readonly)

Returns the value of attribute type.



21
22
23
# File 'lib/skyfall/firehose/message.rb', line 21

def type
  @type
end

#type_objectObject (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)

  message_class = 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

  message = message_class.allocate
  message.send(:initialize, type_object, data_object)
  message
end

Instance Method Details

#inspectObject



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_variablesObject



63
64
65
# File 'lib/skyfall/firehose/message.rb', line 63

def inspectable_variables
  instance_variables - [:@type_object, :@data_object, :@blocks]
end

#operationsObject



55
56
57
# File 'lib/skyfall/firehose/message.rb', line 55

def operations
  []
end

#timeObject



59
60
61
# File 'lib/skyfall/firehose/message.rb', line 59

def time
  @time ||= @data_object['time'] && Time.parse(@data_object['time'])
end