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.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#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.
- #new_message_hash ⇒ Object
- #to_hash ⇒ Object
- #to_rrepr ⇒ Object
Constructor Details
#initialize(object, selector, opts, *args) ⇒ Message
Returns a new instance of Message.
8 9 10 11 12 13 |
# File 'lib/ayl/message.rb', line 8 def initialize(object, selector, opts, *args) @object = object @selector = selector = 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 |
#code ⇒ Object
Returns the value of attribute code.
6 7 8 |
# File 'lib/ayl/message.rb', line 6 def code @code 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 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
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ayl/message.rb', line 15 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..failed_job_handler = ['failed_job_handler'] if ['failed_job_handler'] m..failed_job_count = ['failed_job_count'] if ['failed_job_handler'] == 'decay' && ['failed_job_count'] m..failed_job_delay = ['failed_job_delay'] if ['failed_job_handler'] == 'decay' && ['failed_job_delay'] end end |
Instance Method Details
#evaluate(top_binding) ⇒ Object
56 57 58 59 |
# File 'lib/ayl/message.rb', line 56 def evaluate(top_binding) code_to_eval = to_rrepr eval(code_to_eval, top_binding, code_to_eval, 1) end |
#new_message_hash ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ayl/message.rb', line 43 def { :type => :ayl, :failed_job_handler => .failed_job_handler, :code => to_rrepr }.tap do | h | if .failed_job_handler == 'decay' h[:failed_job_count] = .failed_job_count h[:failed_job_delay] = .failed_job_delay end end end |
#to_hash ⇒ Object
39 40 41 |
# File 'lib/ayl/message.rb', line 39 def to_hash ||= end |
#to_rrepr ⇒ Object
35 36 37 |
# File 'lib/ayl/message.rb', line 35 def to_rrepr @code ||= %Q{#{@object.to_rrepr}.#{@selector}(#{@arguments.to_rrepr[1...-1]})} end |