Class: Miasma::Types::Model
- Inherits:
-
Data
- Object
- Data
- Miasma::Types::Model
- Includes:
- Utils::Memoization
- Defined in:
- lib/miasma/types/model.rb
Overview
Base model
Direct Known Subclasses
Models::AutoScale::Group, Models::Compute::Server, Models::LoadBalancer::Balancer, Models::Orchestration::Stack, Models::Orchestration::Stack::Event, Models::Orchestration::Stack::Resource, Models::Storage::Bucket, Models::Storage::File
Instance Attribute Summary (collapse)
-
- (Miasma::Types::Api) api
readonly
Underlying service API.
Class Method Summary (collapse)
-
+ (Model) from_json(api, json)
Build new model from JSON.
Instance Method Summary (collapse)
- - (Object) _memo included from Utils::Memoization
-
- (TrueClass) clear_memoizations!
included
from Utils::Memoization
Remove all memoized values.
-
- (TrueClass, FalseClass) destroy
Destroy the model.
- - (String, Integer) id?
-
- (self) initialize(api, model_data = nil)
constructor
Build new model.
-
- (Object) memoize(key, direct = false) { ... }
included
from Utils::Memoization
Memoize data.
-
- (TrueClass, FalseClass) persisted?
Model is persisted.
-
- (self) reload
Reload the underlying data for model.
-
- (TrueClass, FalseClass) save
Save changes to the model.
-
- (NilClass) unmemoize(key, direct = false)
included
from Utils::Memoization
Remove memoized value.
Constructor Details
- (self) initialize(api, model_data = nil)
Build new model
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/miasma/types/model.rb', line 34 def initialize(api, model_data=nil) @api = api @data = Smash.new @dirty = Smash.new if(model_data) if(model_data.is_a?(Hash)) load_data(model_data) unless model_data.empty? else raise TypeError.new "Expecting `model_data` to be of type `Hash`. Received: `#{model_data.class}`" end end end |
Instance Attribute Details
- (Miasma::Types::Api) api (readonly)
Returns underlying service API
12 13 14 |
# File 'lib/miasma/types/model.rb', line 12 def api @api end |
Class Method Details
+ (Model) from_json(api, json)
Build new model from JSON
21 22 23 24 25 |
# File 'lib/miasma/types/model.rb', line 21 def from_json(api, json) instance = self.new(api) instance.from_json(json) instance end |
Instance Method Details
- (Object) _memo Originally defined in module Utils::Memoization
- (TrueClass) clear_memoizations! Originally defined in module Utils::Memoization
Remove all memoized values
- (TrueClass, FalseClass) destroy
Destroy the model
64 65 66 67 68 69 70 71 72 |
# File 'lib/miasma/types/model.rb', line 64 def destroy if(persisted?) perform_destroy reload true else false end end |
- (String, Integer) id?
89 90 91 |
# File 'lib/miasma/types/model.rb', line 89 def id? data[:id] || dirty[:id] end |
- (Object) memoize(key, direct = false) { ... } Originally defined in module Utils::Memoization
Memoize data
- (TrueClass, FalseClass) persisted?
Returns model is persisted
84 85 86 |
# File 'lib/miasma/types/model.rb', line 84 def persisted? id? end |
- (self) reload
Reload the underlying data for model
77 78 79 80 81 |
# File 'lib/miasma/types/model.rb', line 77 def reload clear_memoizations! perform_reload self end |
- (TrueClass, FalseClass) save
Save changes to the model
51 52 53 54 55 56 57 58 |
# File 'lib/miasma/types/model.rb', line 51 def save if(dirty?) perform_save reload else false end end |
- (NilClass) unmemoize(key, direct = false) Originally defined in module Utils::Memoization
Remove memoized value