Class: Toq::Message
Overview
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Message
constructor
A new instance of Message.
-
#merge!(message) ⇒ Object
Merges the attributes of another message with self.
-
#prepare_for_tx ⇒ Hash
Prepares the message for transmission (i.e. converts the message to a ‘Hash`).
-
#transmit?(attr) ⇒ Boolean
Decides which attributes should be skipped by #prepare_for_tx.
Constructor Details
#initialize(opts = {}) ⇒ Message
Returns a new instance of Message.
18 19 20 |
# File 'lib/toq/message.rb', line 18 def initialize( opts = {} ) opts.each_pair { |k, v| send( "#{k}=".to_sym, v ) } end |
Instance Method Details
#merge!(message) ⇒ Object
Merges the attributes of another message with self.
(The param doesn’t really have to be a message, any object will do.)
27 28 29 30 31 32 |
# File 'lib/toq/message.rb', line 27 def merge!( ) .instance_variables.each do |var| val = .instance_variable_get( var ) instance_variable_set( var, val ) end end |
#prepare_for_tx ⇒ Hash
Prepares the message for transmission (i.e. converts the message to a ‘Hash`).
Attributes that should not be included can be skipped by implementing #transmit? and returning the appropriate value.
40 41 42 43 44 45 |
# File 'lib/toq/message.rb', line 40 def prepare_for_tx instance_variables.inject({}) do |h, k| h[normalize( k )] = instance_variable_get( k ) if transmit?( k ) h end end |
#transmit?(attr) ⇒ Boolean
Decides which attributes should be skipped by #prepare_for_tx.
51 52 53 |
# File 'lib/toq/message.rb', line 51 def transmit?( attr ) true end |