Class: Rosette::Client::HashResponse
- Inherits:
-
Object
- Object
- Rosette::Client::HashResponse
- Defined in:
- lib/rosette/client/response.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Instance Method Summary collapse
- #error? ⇒ Boolean
-
#initialize(hash) ⇒ HashResponse
constructor
A new instance of HashResponse.
- #method_missing(method, *args, &block) ⇒ Object
-
#respond_to?(method) ⇒ Boolean
responds to everything, returns nil for any unset attributes.
- #success? ⇒ Boolean
Constructor Details
#initialize(hash) ⇒ HashResponse
Returns a new instance of HashResponse.
20 21 22 |
# File 'lib/rosette/client/response.rb', line 20 def initialize(hash) @attributes = hash end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
32 33 34 35 36 |
# File 'lib/rosette/client/response.rb', line 32 def method_missing(method, *args, &block) if attributes.include?(method.to_s) attributes[method.to_s] end end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
18 19 20 |
# File 'lib/rosette/client/response.rb', line 18 def attributes @attributes end |
Instance Method Details
#error? ⇒ Boolean
24 25 26 |
# File 'lib/rosette/client/response.rb', line 24 def error? attributes.include?('error') end |
#respond_to?(method) ⇒ Boolean
responds to everything, returns nil for any unset attributes
39 40 41 |
# File 'lib/rosette/client/response.rb', line 39 def respond_to?(method) true end |
#success? ⇒ Boolean
28 29 30 |
# File 'lib/rosette/client/response.rb', line 28 def success? !error? end |