Class: ActiveMessaging::BaseMessage

Inherits:
Object
  • Object
show all
Defined in:
lib/activemessaging/base_message.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body = nil, id = nil, headers = {}, destination = nil) ⇒ BaseMessage

Returns a new instance of BaseMessage.



6
7
8
# File 'lib/activemessaging/base_message.rb', line 6

def initialize(body=nil, id=nil, headers={}, destination=nil)
  @body, @id, @headers, @destination = body, id, headers, destination
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



4
5
6
# File 'lib/activemessaging/base_message.rb', line 4

def body
  @body
end

#destinationObject

Returns the value of attribute destination.



4
5
6
# File 'lib/activemessaging/base_message.rb', line 4

def destination
  @destination
end

#headersObject

Returns the value of attribute headers.



4
5
6
# File 'lib/activemessaging/base_message.rb', line 4

def headers
  @headers
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/activemessaging/base_message.rb', line 4

def id
  @id
end

Instance Method Details

#dupObject



14
15
16
17
18
19
20
21
# File 'lib/activemessaging/base_message.rb', line 14

def dup
  super.tap do |copy|
    [:body, :id, :headers, :destination].each do |field_name|
      value = send field_name
      copy.send "#{field_name}=", (value.duplicable? ? value.dup : value)
    end
  end
end

#matches_subscription?(subscription) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/activemessaging/base_message.rb', line 10

def matches_subscription?(subscription)
  self.destination.to_s == subscription.destination.value.to_s
end

#to_sObject



23
24
25
# File 'lib/activemessaging/base_message.rb', line 23

def to_s      
  "<#{self.class.name} id='#{id}' headers='#{headers.inspect}' body='#{body}' >"
end