Sha256: 89c789f0e224ad61a82f237abecd90bff0663581319c1c298fa1515b116cd2c8

Contents?: true

Size: 520 Bytes

Versions: 3

Compression:

Stored size: 520 Bytes

Contents

module Toy
  module Reloadable
    extend ActiveSupport::Concern

    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.13.0 lib/toy/reloadable.rb
toystore-0.12.0 lib/toy/reloadable.rb
toystore-0.11.0 lib/toy/reloadable.rb