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.



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

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

#seqObject (readonly)

Returns the value of attribute seq.



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

def seq
  @seq
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

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

  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 '#sync'      then Firehose::SyncMessage
    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



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_variablesObject



69
70
71
# File 'lib/skyfall/firehose/message.rb', line 69

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

#operationsObject



57
58
59
# File 'lib/skyfall/firehose/message.rb', line 57

def operations
  []
end

#timeObject



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

Returns:

  • (Boolean)


61
62
63
# File 'lib/skyfall/firehose/message.rb', line 61

def unknown?
  self.is_a?(Firehose::UnknownMessage)
end