Sha256: d90b1ce167b93346b5ceafba1ae8713b95a86aec00d2016ef3d8814505129bbc

Contents?: true

Size: 485 Bytes

Versions: 3

Compression:

Stored size: 485 Bytes

Contents

module Toy
  module Reloadable
    def reload
      if attrs = adapter.read(id)
        attrs['id'] = 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(id)
      end
      self
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
toystore-0.10.4 lib/toy/reloadable.rb
toystore-0.10.3 lib/toy/reloadable.rb
toystore-0.10.2 lib/toy/reloadable.rb