Module: Relaxo::Model::Document
- Includes:
- Comparable
- Defined in:
- lib/relaxo/model/document.rb
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- TYPE =
'type'
Class Method Summary collapse
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Equality is done only on id.
-
#after_create ⇒ Object
Set any default values:.
- #after_delete ⇒ Object
- #after_fetch ⇒ Object
- #after_save ⇒ Object
- #before_delete ⇒ Object
-
#before_save ⇒ Object
Update any calculations:.
- #changed?(key) ⇒ Boolean
- #delete ⇒ Object
-
#dup(database = @database) ⇒ Object
Duplicate the model object, and possibly change the database it is connected to.
- #id ⇒ Object
- #rev ⇒ Object
-
#save ⇒ Object
Save the model object, raises ‘ValidationErrors` if there are validation errors.
- #saved? ⇒ Boolean
- #type ⇒ Object
Class Method Details
.included(child) ⇒ Object
42 43 44 45 |
# File 'lib/relaxo/model/document.rb', line 42 def self.included(child) child.send(:include, Component) child.send(:extend, ClassMethods) end |
Instance Method Details
#<=>(other) ⇒ Object
Equality is done only on id
149 150 151 |
# File 'lib/relaxo/model/document.rb', line 149 def <=> other self.id <=> other.id end |
#after_create ⇒ Object
Set any default values:
145 146 |
# File 'lib/relaxo/model/document.rb', line 145 def after_create end |
#after_delete ⇒ Object
130 131 |
# File 'lib/relaxo/model/document.rb', line 130 def after_delete end |
#after_fetch ⇒ Object
141 142 |
# File 'lib/relaxo/model/document.rb', line 141 def after_fetch end |
#after_save ⇒ Object
103 104 |
# File 'lib/relaxo/model/document.rb', line 103 def after_save end |
#before_delete ⇒ Object
127 128 |
# File 'lib/relaxo/model/document.rb', line 127 def before_delete end |
#before_save ⇒ Object
Update any calculations:
100 101 |
# File 'lib/relaxo/model/document.rb', line 100 def before_save end |
#changed?(key) ⇒ Boolean
87 88 89 |
# File 'lib/relaxo/model/document.rb', line 87 def changed? key @changed.include? key.to_s end |
#delete ⇒ Object
133 134 135 136 137 138 139 |
# File 'lib/relaxo/model/document.rb', line 133 def delete before_delete @database.delete(@attributes) after_delete end |
#dup(database = @database) ⇒ Object
Duplicate the model object, and possibly change the database it is connected to. You will potentially have two objects referring to the same record.
107 108 109 110 111 112 113 |
# File 'lib/relaxo/model/document.rb', line 107 def dup(database = @database) clone = self.class.new(database, @attributes.dup) clone.after_fetch return clone end |
#id ⇒ Object
79 80 81 |
# File 'lib/relaxo/model/document.rb', line 79 def id @attributes[ID] end |
#rev ⇒ Object
91 92 93 |
# File 'lib/relaxo/model/document.rb', line 91 def rev @attributes[REV] end |
#save ⇒ Object
Save the model object, raises ‘ValidationErrors` if there are validation errors.
116 117 118 119 120 121 122 123 124 125 |
# File 'lib/relaxo/model/document.rb', line 116 def save before_save errors = self.flatten! raise ValidationErrors.new(errors) if errors.size > 0 @database.save(@attributes) after_save end |
#saved? ⇒ Boolean
83 84 85 |
# File 'lib/relaxo/model/document.rb', line 83 def saved? @attributes.key? ID end |
#type ⇒ Object
95 96 97 |
# File 'lib/relaxo/model/document.rb', line 95 def type @attributes[TYPE] end |