Class: Cubscout::Object
- Inherits:
-
Object
- Object
- Cubscout::Object
- Includes:
- Scopes
- Defined in:
- lib/cubscout/object.rb
Overview
the Object class is the base class for any object retrieved from the Helpscout API. it’s attributes can be read either as they are returned (usually camel case) but also in snake case.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Instance Method Summary collapse
-
#initialize(attributes) ⇒ Object
constructor
A new instance of Object.
- #method_missing(method_name, *args, &block) ⇒ Object
Methods included from Scopes
Constructor Details
#initialize(attributes) ⇒ Object
Returns a new instance of Object.
14 15 16 17 |
# File 'lib/cubscout/object.rb', line 14 def initialize(attributes) # Dirty deep_transform_keys to strings @attributes = JSON.parse(attributes.to_json) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/cubscout/object.rb', line 19 def method_missing(method_name, *args, &block) key = camelize(method_name) return super unless @attributes.key?(key) @attributes[key] end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
12 13 14 |
# File 'lib/cubscout/object.rb', line 12 def attributes @attributes end |