Class: Ayl::Message
- Inherits:
-
Object
- Object
- Ayl::Message
- Defined in:
- lib/ayl/message.rb
Instance Attribute Summary collapse
-
#arguments ⇒ Object
Returns the value of attribute arguments.
-
#object ⇒ Object
Returns the value of attribute object.
-
#options ⇒ Object
Returns the value of attribute options.
-
#selector ⇒ Object
Returns the value of attribute selector.
Class Method Summary collapse
Instance Method Summary collapse
- #evaluate(top_binding) ⇒ Object
-
#initialize(object, selector, opts, *args) ⇒ Message
constructor
A new instance of Message.
- #to_hash ⇒ Object
- #to_rrepr ⇒ Object
Constructor Details
#initialize(object, selector, opts, *args) ⇒ Message
Returns a new instance of Message.
7 8 9 10 11 12 |
# File 'lib/ayl/message.rb', line 7 def initialize(object, selector, opts, *args) @object = object @selector = selector @options = opts @arguments = args end |
Instance Attribute Details
#arguments ⇒ Object
Returns the value of attribute arguments.
5 6 7 |
# File 'lib/ayl/message.rb', line 5 def arguments @arguments end |
#object ⇒ Object
Returns the value of attribute object.
5 6 7 |
# File 'lib/ayl/message.rb', line 5 def object @object end |
#options ⇒ Object
Returns the value of attribute options.
5 6 7 |
# File 'lib/ayl/message.rb', line 5 def @options end |
#selector ⇒ Object
Returns the value of attribute selector.
5 6 7 |
# File 'lib/ayl/message.rb', line 5 def selector @selector end |
Class Method Details
.from_hash(message_hash) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ayl/message.rb', line 14 def self.from_hash() raise Ayl::UnrecoverableMessageException, "parameter must be a hash" unless .is_a?(Hash) raise Ayl::UnrecoverableMessageException, "not a valid message hash" if [:type] != :ayl || [:code].nil? raise Ayl::UnrecoverableMessageException, "No code provided in job: #{job.body}" if [:code].nil? code = [:code] Message.new(nil, nil, MessageOptions.new).tap do | m | m.send(:message_hash=, ) m.send(:code=, code) m..decay_failed_job = [:decay_failed_job] if [:decay_failed_job] end end |
Instance Method Details
#evaluate(top_binding) ⇒ Object
41 42 43 44 |
# File 'lib/ayl/message.rb', line 41 def evaluate(top_binding) code_to_eval = to_rrepr eval(code_to_eval, top_binding, code_to_eval, 1) end |
#to_hash ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/ayl/message.rb', line 33 def to_hash @message_hash ||= { :type => :ayl, :decay_failed_job => .decay_failed_job, :code => to_rrepr } end |
#to_rrepr ⇒ Object
29 30 31 |
# File 'lib/ayl/message.rb', line 29 def to_rrepr @code ||= %Q{#{@object.to_rrepr}.#{@selector}(#{@arguments.to_rrepr[1...-1]})} end |