Module: Architect4r::Model::Persistency::InstanceMethods
- Defined in:
- lib/architect4r/model/persistency.rb
Instance Method Summary collapse
-
#create!(options = {}) ⇒ Object
Creates the document in the db.
- #destroyed? ⇒ Boolean
- #id ⇒ Object (also: #to_key, #to_param)
- #new? ⇒ Boolean (also: #new_record?)
- #persisted? ⇒ Boolean
- #save(options = {}) ⇒ Object
- #save! ⇒ Object
-
#update_attributes(hash) ⇒ Object
Update the document’s attributes and save.
Instance Method Details
#create!(options = {}) ⇒ Object
Creates the document in the db. Raises an exception if the document is not created properly.
14 15 16 |
# File 'lib/architect4r/model/persistency.rb', line 14 def create!( = {}) self.fail_validate!(self) unless self.create() end |
#destroyed? ⇒ Boolean
43 44 45 |
# File 'lib/architect4r/model/persistency.rb', line 43 def destroyed? !!@_destroyed end |
#id ⇒ Object Also known as: to_key, to_param
27 28 29 30 31 32 33 |
# File 'lib/architect4r/model/persistency.rb', line 27 def id @id ||= if raw_data && raw_data['self'].present? raw_data['self'].split('/').last.to_i else nil end end |
#new? ⇒ Boolean Also known as: new_record?
37 38 39 40 |
# File 'lib/architect4r/model/persistency.rb', line 37 def new? # Persisted objects always have an id. id.nil? end |
#persisted? ⇒ Boolean
47 48 49 |
# File 'lib/architect4r/model/persistency.rb', line 47 def persisted? !new? && !destroyed? end |
#save(options = {}) ⇒ Object
18 19 20 |
# File 'lib/architect4r/model/persistency.rb', line 18 def save( = {}) self.new? ? create() : update() end |
#save! ⇒ Object
22 23 24 25 |
# File 'lib/architect4r/model/persistency.rb', line 22 def save! self.class.fail_validate!(self) unless self.save true end |
#update_attributes(hash) ⇒ Object
Update the document’s attributes and save. For example:
52 53 54 55 |
# File 'lib/architect4r/model/persistency.rb', line 52 def update_attributes(hash) update_attributes_without_saving hash save end |