Class: Amiando::Result
- Inherits:
-
Object
- Object
- Amiando::Result
- Includes:
- Autorun
- Defined in:
- lib/amiando/result.rb
Overview
This object is intended to be used when an api will return value that is not a resource object (a User, an Event, etc), but due to the delayed nature of doing requests in parallel, can’t be initialized from the beginning.
After the object is populated, you can ask the result with the result method.
Instance Attribute Summary collapse
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#request ⇒ Object
Returns the value of attribute request.
-
#response ⇒ Object
Returns the value of attribute response.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#success ⇒ Object
readonly
Returns the value of attribute success.
Instance Method Summary collapse
-
#initialize(&block) ⇒ Result
constructor
A new instance of Result.
- #populate(response_body) ⇒ Object
Methods included from Autorun
Constructor Details
#initialize(&block) ⇒ Result
Returns a new instance of Result.
18 19 20 21 22 23 24 |
# File 'lib/amiando/result.rb', line 18 def initialize(&block) @populator = block @populator ||= Proc.new do |response_body, result| result.errors = response_body['errors'] response_body['success'] end end |
Instance Attribute Details
#errors ⇒ Object
Returns the value of attribute errors.
13 14 15 |
# File 'lib/amiando/result.rb', line 13 def errors @errors end |
#request ⇒ Object
Returns the value of attribute request.
13 14 15 |
# File 'lib/amiando/result.rb', line 13 def request @request end |
#response ⇒ Object
Returns the value of attribute response.
13 14 15 |
# File 'lib/amiando/result.rb', line 13 def response @response end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
14 15 16 |
# File 'lib/amiando/result.rb', line 14 def result @result end |
#success ⇒ Object (readonly)
Returns the value of attribute success.
14 15 16 |
# File 'lib/amiando/result.rb', line 14 def success @success end |
Instance Method Details
#populate(response_body) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/amiando/result.rb', line 26 def populate(response_body) if @populator.arity == 1 @result = @populator.call(response_body) elsif @populator.arity == 2 @result = @populator.call(response_body, self) end @success = response_body['success'] end |