class Qwrapper::Message

Attributes

hash[R]
original_body[R]

Public Class Methods

new(body) click to toggle source
# File lib/qwrapper/message.rb, line 8
def initialize(body)
  raise ArgumentError.new "Message body cannot be blank" if body.nil? or body.empty?
  @original_body = body
  begin
    begin
      @hash = eval(body.to_s)
    rescue SyntaxError => ex
      @hash = JSON.parse(body.to_s)
    end
    logger.info "Message evaluated: #{@hash}"
  rescue Exception => ex
    logger.error "Message body cannot be evaluated: #{body}"
    raise ex
  end
  validate!
end

Public Instance Methods

action() click to toggle source
# File lib/qwrapper/message.rb, line 25
def action
  ((hash[:action] || hash["action"])).to_sym
end
method_missing(m, *args, &block) click to toggle source
# File lib/qwrapper/message.rb, line 29
def method_missing(m, *args, &block)
  hash[m.to_s] || hash[m.to_s.to_sym]
end

Private Instance Methods

logger() click to toggle source
# File lib/qwrapper/message.rb, line 39
def logger
  Qwrapper.logger
end
validate!() click to toggle source
# File lib/qwrapper/message.rb, line 35
def validate!
  # TODO: Raise NotImplementedError? Client should implement their own custom error
end