Sha256: 3ac0f79c0a69b36fb26b593bef49aa577694fba9c17dcdd4f8970821ca324666

Contents?: true

Size: 641 Bytes

Versions: 1

Compression:

Stored size: 641 Bytes

Contents

module Undo
  class Model < SimpleDelegator
    def initialize(object, options = {})
      @object = object
      @config = config.with options
      super object
    end

    def uuid
      @uuid ||= object.respond_to?(:uuid) ? object.uuid : generate_uuid
    end

    def method_missing(method, *args, &block)
      store if config.mutator_methods.include? method
      super method, *args, &block
    end

    private
    attr_reader :object

    def generate_uuid
      config.uuid_generator.call object
    end

    def store
      config.storage.put uuid, object
    end

    def config
      @config ||= Undo.config
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
undo-0.0.1 lib/undo/model.rb