Module: Undo

Defined in:
lib/undo.rb,
lib/undo/config.rb,
lib/undo/version.rb,
lib/undo/wrapper.rb,
lib/undo/storage/memory.rb,
lib/undo/serializer/null.rb

Defined Under Namespace

Modules: Serializer, Storage Classes: Config, Wrapper

Constant Summary collapse

VERSION =
"0.1.1"

Class Method Summary collapse

Class Method Details

.configure(&block) ⇒ Object



6
7
8
# File 'lib/undo.rb', line 6

def self.configure(&block)
  block_given? ? block.call(config) : config
end

.restore(uuid, options = {}) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/undo.rb', line 19

def self.restore(uuid, options = {})
  config.with(options) do |config|
    config.serializer.deserialize config.storage.fetch(uuid),
                                  config.filter(options)

  end
end

.store(object, options = {}) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/undo.rb', line 10

def self.store(object, options = {})
  config.with(options) do |config|
    uuid(object, options).tap do |uuid|
      config.storage.put uuid,
                         config.serializer.serialize(object, config.filter(options))
    end
  end
end

.wrap(object, options = {}) ⇒ Object



27
28
29
30
31
32
# File 'lib/undo.rb', line 27

def self.wrap(object, options = {})
  options[:uuid] ||= uuid object, options
  config.with(options) do |config|
    Wrapper.new object, options.merge(mutator_methods: config.mutator_methods)
  end
end