Class: Pubsubstub::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/pubsubstub/event.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, options = {}) ⇒ Event

Returns a new instance of Event.



5
6
7
8
9
10
# File 'lib/pubsubstub/event.rb', line 5

def initialize(data, options = {})
  @id = options[:id] || time_now
  @name = options[:name]
  @retry_after = options[:retry_after]
  @data = data
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



3
4
5
# File 'lib/pubsubstub/event.rb', line 3

def data
  @data
end

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/pubsubstub/event.rb', line 3

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/pubsubstub/event.rb', line 3

def name
  @name
end

#retry_afterObject (readonly)

Returns the value of attribute retry_after.



3
4
5
# File 'lib/pubsubstub/event.rb', line 3

def retry_after
  @retry_after
end

Class Method Details

.from_json(json) ⇒ Object



20
21
22
23
# File 'lib/pubsubstub/event.rb', line 20

def self.from_json(json)
  hash = JSON.load(json)
  new(hash['data'], name: hash['name'], id: hash['id'], retry_after: hash['retry_after'])
end

Instance Method Details

#==(other) ⇒ Object



25
26
27
# File 'lib/pubsubstub/event.rb', line 25

def ==(other)
  id == other.id && name == other.name && data == other.data && retry_after == other.retry_after
end

#to_jsonObject



12
13
14
# File 'lib/pubsubstub/event.rb', line 12

def to_json
  {id: @id, name: @name, data: @data, retry_after: @retry_after}.to_json
end

#to_messageObject



16
17
18
# File 'lib/pubsubstub/event.rb', line 16

def to_message
  @message ||= build_message
end