Class: RSwim::Message

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(to, from, type, payload = {}) ⇒ Message

Returns a new instance of Message.



7
8
9
10
11
12
# File 'lib/rswim/message.rb', line 7

def initialize(to, from, type, payload = {})
  @to = to
  @from = from
  @type = type
  @payload = payload
end

Instance Attribute Details

#fromObject (readonly)

Returns the value of attribute from.



5
6
7
# File 'lib/rswim/message.rb', line 5

def from
  @from
end

#payloadObject (readonly)

Returns the value of attribute payload.



5
6
7
# File 'lib/rswim/message.rb', line 5

def payload
  @payload
end

#toObject (readonly)

Returns the value of attribute to.



5
6
7
# File 'lib/rswim/message.rb', line 5

def to
  @to
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/rswim/message.rb', line 5

def type
  @type
end

Instance Method Details

#==(other) ⇒ Object



18
19
20
# File 'lib/rswim/message.rb', line 18

def ==(other)
  %i[to from type payload].all? { |a| send(a) == other.send(a) }
end

#to_sObject



14
15
16
# File 'lib/rswim/message.rb', line 14

def to_s
  "message of type #{type} from #{from} to #{to} with #{payload[:updates].to_a.size} updates"
end