Class: Stacktor::Core::Resource
- Inherits:
-
Object
- Object
- Stacktor::Core::Resource
- Defined in:
- lib/stacktor/core/resource.rb
Direct Known Subclasses
Identity::V2::Token, Swift::V1::Container, Swift::V1::ContainerObject
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#data ⇒ Object
Returns the value of attribute data.
Instance Method Summary collapse
- #[](field) ⇒ Object
- #[]=(field, val) ⇒ Object
- #handle_data(data, opts = {}) ⇒ Object
- #headers ⇒ Object
-
#initialize(data, client, opts = {}) ⇒ Resource
constructor
A new instance of Resource.
- #method_missing(method, *args, &block) ⇒ Object
Constructor Details
#initialize(data, client, opts = {}) ⇒ Resource
Returns a new instance of Resource.
9 10 11 12 |
# File 'lib/stacktor/core/resource.rb', line 9 def initialize(data, client, opts={}) @client = client self.handle_data(data, opts) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
34 35 36 |
# File 'lib/stacktor/core/resource.rb', line 34 def method_missing(method, *args, &block) return self[method] end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
7 8 9 |
# File 'lib/stacktor/core/resource.rb', line 7 def client @client end |
#data ⇒ Object
Returns the value of attribute data.
7 8 9 |
# File 'lib/stacktor/core/resource.rb', line 7 def data @data end |
Instance Method Details
#[](field) ⇒ Object
23 24 25 |
# File 'lib/stacktor/core/resource.rb', line 23 def [](field) @data[field.to_s] || @options[:headers][field.to_s] end |
#[]=(field, val) ⇒ Object
26 27 28 |
# File 'lib/stacktor/core/resource.rb', line 26 def []=(field,val) @data[field.to_s]=val end |
#handle_data(data, opts = {}) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/stacktor/core/resource.rb', line 14 def handle_data(data, opts={}) if data.is_a?(String) data = JSON.parse(data) end @data = data || {} @options = opts @options[:headers] ||= {} end |
#headers ⇒ Object
30 31 32 |
# File 'lib/stacktor/core/resource.rb', line 30 def headers @options[:headers] end |