Class: Miasma::Models::Orchestration::Stack::Resource
- Inherits:
-
Types::Model
- Object
- Types::Data
- Types::Model
- Miasma::Models::Orchestration::Stack::Resource
- Includes:
- Utils::Immutable
- Defined in:
- lib/miasma/models/orchestration/resource.rb
Overview
Stack resource
Instance Attribute Summary collapse
-
#stack ⇒ Object
readonly
Returns the value of attribute stack.
Attributes inherited from Types::Model
Instance Method Summary collapse
-
#dereference ⇒ Miasma::Types::Model
Provides mapped resource class.
-
#expand ⇒ Miasma::Types::Model
(also: #instance)
Provide proper instance from resource.
-
#initialize(stack, args = {}) ⇒ Resource
constructor
A new instance of Resource.
-
#perform_reload ⇒ Object
Proxy reload action up to the API.
-
#within?(api, collection) ⇒ TrueClass, FalseClass
Resource is within the collection on the api.
Methods included from Utils::Immutable
#frozen_valid_state, included, #save
Methods inherited from Types::Model
#destroy, from_json, #id?, #persisted?, #reload, #save
Methods included from Utils::Memoization
#_memo, #clear_memoizations!, #memoize, #unmemoize
Methods inherited from Types::Data
from_json, #from_json, #to_json
Methods included from Utils::Lazy
Constructor Details
#initialize(stack, args = {}) ⇒ Resource
Returns a new instance of Resource.
21 22 23 24 |
# File 'lib/miasma/models/orchestration/resource.rb', line 21 def initialize(stack, args={}) @stack = stack super stack.api, args end |
Instance Attribute Details
#stack ⇒ Object (readonly)
Returns the value of attribute stack.
19 20 21 |
# File 'lib/miasma/models/orchestration/resource.rb', line 19 def stack @stack end |
Instance Method Details
#dereference ⇒ Miasma::Types::Model
Returns provides mapped resource class.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/miasma/models/orchestration/resource.rb', line 27 def dereference # Insert provider to namespace provider_const = self.class.name.split('::').insert(3, Utils.camel(api.provider)) provider_const.slice!(-2, 2) # Insert mapping constant name and fetch const = provider_const.push(:RESOURCE_MAPPING).inject(Object) do |memo, konst| res = memo.const_get(konst) break unless res res end unless(const[self.type]) raise KeyError.new "Failed to locate requested mapping! (`#{self.type}`)" end const[self.type] end |
#expand ⇒ Miasma::Types::Model Also known as: instance
Provide proper instance from resource
46 47 48 49 |
# File 'lib/miasma/models/orchestration/resource.rb', line 46 def info = dereference api.api_for(info[:api]).send(info[:collection]).get(self.id) end |
#perform_reload ⇒ Object
Proxy reload action up to the API
53 54 55 |
# File 'lib/miasma/models/orchestration/resource.rb', line 53 def perform_reload api.resource_reload(self) end |
#within?(api, collection) ⇒ TrueClass, FalseClass
Resource is within the collection on the api
62 63 64 65 66 67 68 69 70 |
# File 'lib/miasma/models/orchestration/resource.rb', line 62 def within?(api, collection) begin info = dereference info[:api] == api && info[:collection] == collection rescue KeyError false end end |