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.0"

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



18
19
20
21
22
# File 'lib/undo.rb', line 18

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

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



10
11
12
13
14
15
16
# 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)
    end
  end
end

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



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

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