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

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!(options = {})
  self.fail_validate!(self) unless self.create(options)
end

#destroyed?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/architect4r/model/persistency.rb', line 37

def destroyed?
  !!@_destroyed
end

#idObject 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?

Returns:

  • (Boolean)


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

Returns:

  • (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(options = {})
  self.new? ? create(options) : update(options)
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