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)
-
- (Miasma::Types::Api) api
inherited
from Types::Model
readonly
Underlying service API.
-
- (Object) stack
readonly
Returns the value of attribute stack.
Instance Method Summary (collapse)
-
- (Miasma::Types::Model) dereference
Provides mapped resource class.
-
- (Miasma::Types::Model) expand
(also: #instance)
Provide proper instance from resource.
-
- (Object) frozen_valid_state(*args)
included
from Utils::Immutable
Freezes underlying data hash.
-
- (Resource) initialize(stack, args = {})
constructor
A new instance of Resource.
-
- (Object) perform_reload
Proxy reload action up to the API.
- - (Object) save included from Utils::Immutable
-
- (TrueClass, FalseClass) within?(api, collection)
Resource is within the collection on the api.
Constructor Details
- (Resource) initialize(stack, args = {})
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
- (Miasma::Types::Api) api (readonly) Originally defined in class Types::Model
Returns underlying service API
- (Object) stack (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
- (Miasma::Types::Model) dereference
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 |
- (Miasma::Types::Model) expand 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 |
- (Object) frozen_valid_state(*args) Originally defined in module Utils::Immutable
Freezes underlying data hash
- (Object) perform_reload
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 |
- (Object) save Originally defined in module Utils::Immutable
- (TrueClass, FalseClass) within?(api, collection)
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 |