Class: Pio::Echo::Message

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/pio/echo/message.rb

Overview

Base class of Echo request and reply.

Direct Known Subclasses

Reply, Request

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message_type, user_options = {}) ⇒ Message

Returns a new instance of Message.



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/pio/echo/message.rb', line 26

def initialize(message_type, user_options = {})
  if user_options.respond_to?(:to_i)
    @options = { transaction_id: user_options.to_i,
                 message_type: message_type }
  elsif user_options.respond_to?(:[])
    @options = user_options.dup.merge(message_type: message_type)
    handle_user_hash_options
  else
    fail TypeError
  end
  @echo = Format.new(@options)
end

Class Method Details

.create_from(echo) ⇒ Object



20
21
22
23
24
# File 'lib/pio/echo/message.rb', line 20

def self.create_from(echo)
  message = allocate
  message.instance_variable_set :@echo, echo
  message
end