Class: Miasma::Types::ThinModel
- Defined in:
- lib/miasma/types/thin_model.rb
Overview
Base data container
Direct Known Subclasses
Models::AutoScale::Group::Balancer, Models::AutoScale::Group::Server, Models::Compute::Server::Network, Models::LoadBalancer::Balancer::Server, Models::LoadBalancer::Balancer::ServerState
Instance Attribute Summary collapse
-
#api ⇒ Miasma::Types::Api
readonly
Service API.
Class Method Summary collapse
-
.model(klass = nil) ⇒ Class
Get/Set fat model.
Instance Method Summary collapse
-
#expand ⇒ Miasma::Types::Model
(also: #instance)
Build fat model instance.
-
#initialize(api, args = {}) ⇒ ThinModel
constructor
Build new instance.
-
#model ⇒ Class
Associated model class.
- #persisted? ⇒ FalseClass
Methods inherited from Data
from_json, #from_json, #to_json
Constructor Details
#initialize(api, args = {}) ⇒ ThinModel
Build new instance
38 39 40 41 |
# File 'lib/miasma/types/thin_model.rb', line 38 def initialize(api, args = {}) @api = api super args end |
Instance Attribute Details
#api ⇒ Miasma::Types::Api (readonly)
Returns service API.
32 33 34 |
# File 'lib/miasma/types/thin_model.rb', line 32 def api @api end |
Class Method Details
.model(klass = nil) ⇒ Class
Get/Set fat model
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/miasma/types/thin_model.rb', line 14 def model(klass = nil) if klass unless klass.ancestors.include?(Miasma::Types::Model) raise TypeError.new "Expecting `Miasma::Types::Model` subclass! (got #{klass})" else self._model = klass end end self._model end |
Instance Method Details
#expand ⇒ Miasma::Types::Model Also known as: instance
Build fat model instance
64 65 66 67 68 |
# File 'lib/miasma/types/thin_model.rb', line 64 def inst = model.new(api) inst.data[:id] = self.id inst.reload end |
#model ⇒ Class
Note:
will deconstruct namespace and rebuild using provider
Associated model class
53 54 55 56 57 58 59 |
# File 'lib/miasma/types/thin_model.rb', line 53 def model if self.class.model self.class.model else raise NotImplementedError.new "No associated model for this thin model type (#{self.class})" end end |
#persisted? ⇒ FalseClass
Note:
thin models are always false
45 46 47 |
# File 'lib/miasma/types/thin_model.rb', line 45 def persisted? false end |