Module: Toy::Reloadable

Extended by:
ActiveSupport::Concern
Included in:
DirtyStore, Store
Defined in:
lib/toy/reloadable.rb

Instance Method Summary collapse

Instance Method Details

#reloadObject



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

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