Class: Stannp::Object
- Inherits:
-
Object
- Object
- Stannp::Object
- Defined in:
- lib/stannp/object.rb
Direct Known Subclasses
Batch, Campaign, CampaignCost, Group, Letter, Postcard, Receipt, Recipient, User
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, *args, &block) ⇒ Object
- #respond_to_missing?(method, include_private = false) ⇒ Boolean
Constructor Details
#initialize(attributes) ⇒ Object
Returns a new instance of Object.
9 10 11 |
# File 'lib/stannp/object.rb', line 9 def initialize(attributes) @attributes = OpenStruct.new(attributes) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/stannp/object.rb', line 13 def method_missing(method, *args, &block) value = attributes.send(method, *args, &block) case value when Hash Object.new(value) when Array value.map { |item| item.is_a?(Hash) ? Object.new(item) : item } else value end end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
7 8 9 |
# File 'lib/stannp/object.rb', line 7 def attributes @attributes end |
Instance Method Details
#respond_to_missing?(method, include_private = false) ⇒ Boolean
25 26 27 |
# File 'lib/stannp/object.rb', line 25 def respond_to_missing?(method, include_private = false) attributes.to_h.keys.include?(method) || super end |