Sha256: 8bfbd46a80d7642b41507e944510ac3f81ec45262ab9e8879459169795953f8f

Contents?: true

Size: 985 Bytes

Versions: 1

Compression:

Stored size: 985 Bytes

Contents

require "virtus"

module Undo
  class Config
    include Virtus.model

    attribute :mutator_methods, Array[Symbol], default: [:update, :delete, :destroy]

    attribute :uuid_generator, Proc, default: ->(config, _) {
      require "securerandom"
      ->(object) { SecureRandom.uuid }
    }
    attribute :serializer, Object, default: ->(config, _) {
      require "undo/serializer/null"
      Undo::Serializer::Null.new
    }
    attribute :storage, Object, default: ->(config, _) {
      require "undo/storage/memory"
      Undo::Storage::Memory.new serializer: config.serializer
    }, lazy: true

    def with(attribute_updates = {}, &block)
      config = attribute_updates.empty? ? self
                                        : self.class.new(attribute_set.get(self).merge attribute_updates)

      block_given? ? block.call(config) : config
    end

    def filter(options)
      options.delete_if do |key, _|
        attributes.keys.include? key
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
undo-0.1.1 lib/undo/config.rb