Class: Kybus::Storage::Datasource::Model
- Inherits:
-
Object
- Object
- Kybus::Storage::Datasource::Model
- Defined in:
- lib/kybus/storage/datasource/model.rb
Overview
Wraps an object inside a model, this will allow to validate that values are inside the restrictions. It dependes on a repository for storing values.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#repository ⇒ Object
writeonly
Sets the attribute repository.
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#[]=(key, val) ⇒ Object
:nocov: #.
- #create ⇒ Object
-
#initialize(data) ⇒ Model
constructor
A new instance of Model.
-
#run_validations! ⇒ Object
:nocov: #.
- #store ⇒ Object
- #to_json(options = nil) ⇒ Object
Constructor Details
#initialize(data) ⇒ Model
Returns a new instance of Model.
40 41 42 |
# File 'lib/kybus/storage/datasource/model.rb', line 40 def initialize(data) @data = data end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
13 14 15 |
# File 'lib/kybus/storage/datasource/model.rb', line 13 def data @data end |
#repository=(value) ⇒ Object (writeonly)
Sets the attribute repository
14 15 16 |
# File 'lib/kybus/storage/datasource/model.rb', line 14 def repository=(value) @repository = value end |
Instance Method Details
#[](key) ⇒ Object
26 27 28 |
# File 'lib/kybus/storage/datasource/model.rb', line 26 def [](key) @data[key] end |
#[]=(key, val) ⇒ Object
:nocov: #
22 23 24 |
# File 'lib/kybus/storage/datasource/model.rb', line 22 def []=(key, val) @data[key] = val end |
#create ⇒ Object
35 36 37 38 |
# File 'lib/kybus/storage/datasource/model.rb', line 35 def create run_validations! @repository.create(@data) end |
#run_validations! ⇒ Object
:nocov: #
17 18 19 |
# File 'lib/kybus/storage/datasource/model.rb', line 17 def run_validations! puts 'WARN: model with no validations' end |
#store ⇒ Object
30 31 32 33 |
# File 'lib/kybus/storage/datasource/model.rb', line 30 def store run_validations! @repository.store(@data) end |
#to_json(options = nil) ⇒ Object
44 45 46 |
# File 'lib/kybus/storage/datasource/model.rb', line 44 def to_json( = nil) @data.to_json() end |