Module: Architect4r::Model::Persistency
- Extended by:
- ActiveSupport::Concern
- Included in:
- Node, Relationship
- Defined in:
- lib/architect4r/model/persistency.rb
Defined Under Namespace
Modules: ClassMethods
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.
8 9 10 |
# File 'lib/architect4r/model/persistency.rb', line 8 def create!( = {}) self.fail_validate!(self) unless self.create() end |
#destroyed? ⇒ Boolean
37 38 39 |
# File 'lib/architect4r/model/persistency.rb', line 37 def destroyed? !!@_destroyed end |
#id ⇒ Object Also known as: to_key, to_param
21 22 23 24 25 26 27 |
# File 'lib/architect4r/model/persistency.rb', line 21 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?
31 32 33 34 |
# File 'lib/architect4r/model/persistency.rb', line 31 def new? # Persisted objects always have an id. id.nil? end |
#persisted? ⇒ Boolean
41 42 43 |
# File 'lib/architect4r/model/persistency.rb', line 41 def persisted? !new? && !destroyed? end |
#save(options = {}) ⇒ Object
12 13 14 |
# File 'lib/architect4r/model/persistency.rb', line 12 def save( = {}) self.new? ? create() : update() end |
#save! ⇒ Object
16 17 18 19 |
# File 'lib/architect4r/model/persistency.rb', line 16 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:
46 47 48 49 |
# File 'lib/architect4r/model/persistency.rb', line 46 def update_attributes(hash) update_attributes_without_saving hash save end |