Module: Typekit::Element::Persistence
- Included in:
- Record::Kit
- Defined in:
- lib/typekit/element/persistence.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #delete! ⇒ Object
- #deleted? ⇒ Boolean
- #new? ⇒ Boolean
- #persistent? ⇒ Boolean
- #save! ⇒ Object
- #update!(*arguments) ⇒ Object
Class Method Details
.included(base) ⇒ Object
4 5 6 |
# File 'lib/typekit/element/persistence.rb', line 4 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#delete! ⇒ Object
36 37 38 39 40 |
# File 'lib/typekit/element/persistence.rb', line 36 def delete! process(:delete, id) if persistent? @deleted = true true end |
#deleted? ⇒ Boolean
16 17 18 |
# File 'lib/typekit/element/persistence.rb', line 16 def deleted? !!@deleted end |
#new? ⇒ Boolean
8 9 10 |
# File 'lib/typekit/element/persistence.rb', line 8 def new? id.to_s.empty? end |
#persistent? ⇒ Boolean
12 13 14 |
# File 'lib/typekit/element/persistence.rb', line 12 def persistent? !(new? || deleted?) end |
#save! ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/typekit/element/persistence.rb', line 20 def save! if new? element = process(:create, serialize) else element = process(:update, id, serialize) end become(element) true end |
#update!(*arguments) ⇒ Object
30 31 32 33 34 |
# File 'lib/typekit/element/persistence.rb', line 30 def update!(*arguments) assign_attributes(*arguments) become(process(:update, id, serialize)) true end |