Module: Exchanger::Persistence

Included in:
Element
Defined in:
lib/exchanger/persistence.rb

Instance Method Summary collapse

Instance Method Details

#destroyObject



19
20
21
22
23
24
25
# File 'lib/exchanger/persistence.rb', line 19

def destroy
  if new_record?
    false
  else
    delete
  end
end

#new_record?Boolean

Returns:



7
8
9
# File 'lib/exchanger/persistence.rb', line 7

def new_record?
  not id
end

#persisted?Boolean

Returns:



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

def persisted?
  not new_record?
end

#reloadObject

Reloads the Element attributes from Exchanger.



28
29
30
31
32
33
34
35
36
37
# File 'lib/exchanger/persistence.rb', line 28

def reload
  if new_record?
    false
  else
    reloaded_element = self.class.find(self.id)
    @attributes = reloaded_element.attributes
    reset_modifications
    true
  end
end

#saveObject



11
12
13
14
15
16
17
# File 'lib/exchanger/persistence.rb', line 11

def save
  if new_record?
    create
  else
    update
  end
end