Module: Dymos::Persistence

Included in:
Model
Defined in:
lib/dymos/persistence.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#new_recordObject

Returns the value of attribute new_record.



3
4
5
# File 'lib/dymos/persistence.rb', line 3

def new_record
  @new_record
end

Instance Method Details

#deleteObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/dymos/persistence.rb', line 50

def delete

  if persisted?
    builder = ::Dymos::Query::DeleteItem.new

    builder.name(self.table_name).key(indexes).return_values(:all_old)

    @query.each do |k, v|
      builder.send k, *v
    end if @query.present?
    @query={}

    query = builder.build
    @last_execute_query = {command: builder.command, query: query}
    ::Dymos::Client.new.command builder.command, query
  end
  @destroyed = true
  freeze
end

#destroyed?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/dymos/persistence.rb', line 14

def destroyed?
  @destroyed
end

#initialize(params = {}) ⇒ Object



5
6
7
8
# File 'lib/dymos/persistence.rb', line 5

def initialize(params={})
  @new_record = true
  @destroyed = false
end

#new_record?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/dymos/persistence.rb', line 10

def new_record?
  @new_record
end

#persisted?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/dymos/persistence.rb', line 18

def persisted?
  !(new_record? || destroyed?)
end

#saveObject



22
23
24
25
26
27
28
# File 'lib/dymos/persistence.rb', line 22

def save(*)
  run_callbacks :save do
    _put
  end
rescue => e
  false
end

#save!Object



30
31
32
33
34
# File 'lib/dymos/persistence.rb', line 30

def save!(*)
  run_callbacks :save do
    _put || raise(::Dymos::RecordNotSaved)
  end
end

#updateObject



36
37
38
39
40
41
42
# File 'lib/dymos/persistence.rb', line 36

def update(*)
  run_callbacks :save do
    _update
  end
rescue => e
  false
end

#update!Object



44
45
46
47
48
# File 'lib/dymos/persistence.rb', line 44

def update!(*)
  run_callbacks :save do
    _update || raise(::Dymos::RecordNotSaved)
  end
end