Class: Qwrapper::Message
- Inherits:
-
Object
- Object
- Qwrapper::Message
- Includes:
- Loggable
- Defined in:
- lib/qwrapper/message.rb
Instance Attribute Summary collapse
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
-
#original_body ⇒ Object
readonly
Returns the value of attribute original_body.
Instance Method Summary collapse
- #action ⇒ Object
-
#initialize(body) ⇒ Message
constructor
A new instance of Message.
- #method_missing(m, *args, &block) ⇒ Object
Methods included from Loggable
Constructor Details
#initialize(body) ⇒ Message
Returns a new instance of Message.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/qwrapper/message.rb', line 10 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 |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
31 32 33 |
# File 'lib/qwrapper/message.rb', line 31 def method_missing(m, *args, &block) hash[m.to_s] || hash[m.to_s.to_sym] end |
Instance Attribute Details
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
8 9 10 |
# File 'lib/qwrapper/message.rb', line 8 def hash @hash end |
#original_body ⇒ Object (readonly)
Returns the value of attribute original_body.
8 9 10 |
# File 'lib/qwrapper/message.rb', line 8 def original_body @original_body end |
Instance Method Details
#action ⇒ Object
27 28 29 |
# File 'lib/qwrapper/message.rb', line 27 def action ((hash[:action] || hash["action"])).to_sym end |