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)
-
- (Object) errors
Returns the value of attribute errors.
-
- (Object) request
Returns the value of attribute request.
-
- (Object) response
Returns the value of attribute response.
-
- (Object) success
Returns the value of attribute success.
Instance Method Summary (collapse)
-
- (Result) initialize(&block)
constructor
A new instance of Result.
- - (Object) populate(response_body)
Methods included from Autorun
Constructor Details
- (Result) initialize(&block)
A new instance of Result
17 18 19 20 21 22 23 |
# File 'lib/amiando/result.rb', line 17 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
- (Object) errors
Returns the value of attribute errors
13 14 15 |
# File 'lib/amiando/result.rb', line 13 def errors @errors end |
- (Object) request
Returns the value of attribute request
13 14 15 |
# File 'lib/amiando/result.rb', line 13 def request @request end |
- (Object) response
Returns the value of attribute response
13 14 15 |
# File 'lib/amiando/result.rb', line 13 def response @response end |
- (Object) success
Returns the value of attribute success
13 14 15 |
# File 'lib/amiando/result.rb', line 13 def success @success end |
Instance Method Details
- (Object) populate(response_body)
25 26 27 28 29 30 31 32 |
# File 'lib/amiando/result.rb', line 25 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 |