Class: Dupe::Model
- Inherits:
-
Object
- Object
- Dupe::Model
- Defined in:
- lib/superdupe/model.rb,
lib/superdupe/schema.rb,
lib/superdupe/attribute_template.rb
Overview
:nodoc:
Defined Under Namespace
Classes: Schema
Instance Attribute Summary collapse
-
#id_sequence ⇒ Object
readonly
Returns the value of attribute id_sequence.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Instance Method Summary collapse
- #create(attributes = {}) ⇒ Object
- #define(definition_proc) ⇒ Object
-
#initialize(name) ⇒ Model
constructor
A new instance of Model.
-
#run_after_create_callbacks(record) ⇒ Object
called by the Dupe::Database#insert method.
Constructor Details
Instance Attribute Details
#id_sequence ⇒ Object (readonly)
Returns the value of attribute id_sequence.
5 6 7 |
# File 'lib/superdupe/model.rb', line 5 def id_sequence @id_sequence end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/superdupe/model.rb', line 4 def name @name end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
3 4 5 |
# File 'lib/superdupe/model.rb', line 3 def schema @schema end |
Instance Method Details
#create(attributes = {}) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/superdupe/model.rb', line 17 def create(attributes={}) Database::Record.new.tap do |record| record.__model__ = self record.id = @id_sequence.next record.merge! default_record record.merge! transform(attributes) end end |
#define(definition_proc) ⇒ Object
13 14 15 |
# File 'lib/superdupe/model.rb', line 13 def define(definition_proc) definition_proc.call @schema end |
#run_after_create_callbacks(record) ⇒ Object
called by the Dupe::Database#insert method
27 28 29 30 31 |
# File 'lib/superdupe/model.rb', line 27 def run_after_create_callbacks(record) @schema.after_create_callbacks.each do |callback| callback.call record end end |