Module: Toy::Reloadable

Included in:
DirtyStore
Defined in:
lib/toy/reloadable.rb

Instance Method Summary collapse

Instance Method Details

#reloadObject



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/toy/reloadable.rb', line 3

def reload
  if attrs = adapter.read(id)
    attrs['id'] = id
    instance_variables.each        { |ivar| instance_variable_set(ivar, nil) }
    initialize_attributes_with_defaults
    send(:attributes=, attrs, new_record?)
    self.class.lists.each_key      { |name| send(name).reset }
    self.class.references.each_key { |name| send(name).reset }
  else
    raise NotFound.new(id)
  end
  self
end