Class: Djoini::Record
- Inherits:
-
Object
- Object
- Djoini::Record
- Includes:
- Composable
- Defined in:
- lib/djoini/record.rb
Overview
Holds creation and destruction of model, his fields
Instance Method Summary collapse
- #destroy ⇒ Object
-
#initialize(params) ⇒ Record
constructor
A new instance of Record.
- #save ⇒ Object
Methods included from Composable
#features, #method_missing, #respond_to_missing?
Constructor Details
#initialize(params) ⇒ Record
Returns a new instance of Record.
9 10 11 12 13 14 15 |
# File 'lib/djoini/record.rb', line 9 def initialize(params) self.key = params.fetch(:key, nil) self.relation = params.fetch(:relation) features << Fields.new(values: params.fetch(:values, {}), attributes: relation.attributes) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Djoini::Composable
Instance Method Details
#destroy ⇒ Object
25 26 27 |
# File 'lib/djoini/record.rb', line 25 def destroy relation.destroy(key) end |
#save ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/djoini/record.rb', line 17 def save if key relation.update(key, clone_hash) else relation.create(clone_hash) end end |