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
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
Methods included from Utils::Lazy
Constructor Details
#initialize(api, args = {}) ⇒ ThinModel
Build new instance
40 41 42 43 |
# File 'lib/miasma/types/thin_model.rb', line 40 def initialize(api, args={}) @api = api super args end |
Instance Attribute Details
#api ⇒ Miasma::Types::Api (readonly)
Returns service API.
34 35 36 |
# File 'lib/miasma/types/thin_model.rb', line 34 def api @api end |
Class Method Details
.model(klass = nil) ⇒ Class
Get/Set fat model
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/miasma/types/thin_model.rb', line 15 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
66 67 68 69 70 |
# File 'lib/miasma/types/thin_model.rb', line 66 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
55 56 57 58 59 60 61 |
# File 'lib/miasma/types/thin_model.rb', line 55 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
47 48 49 |
# File 'lib/miasma/types/thin_model.rb', line 47 def persisted? false end |