Sha256: ee8ae76fafef77e78add50c5915f8c202b1eab2b9956a7c946f9660c71ae8027

Contents?: true

Size: 869 Bytes

Versions: 3

Compression:

Stored size: 869 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
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
undo-0.1.0 lib/undo/config.rb
undo-0.0.3 lib/undo/config.rb
undo-0.0.2 lib/undo/config.rb