Module: Omnitest::Skeptic::Evidence::Persistable

Included in:
Omnitest::Skeptic::Evidence
Defined in:
lib/omnitest/skeptic/evidence.rb

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#autosave=(value) ⇒ Object (writeonly)

Sets the attribute autosave

Parameters:

  • value

    the value to set the attribute autosave to.



8
9
10
# File 'lib/omnitest/skeptic/evidence.rb', line 8

def autosave=(value)
  @autosave = value
end

#fileObject (readonly)

Returns the value of attribute file.



7
8
9
# File 'lib/omnitest/skeptic/evidence.rb', line 7

def file
  @file
end

Class Method Details

.included(base) ⇒ Object



16
17
18
# File 'lib/omnitest/skeptic/evidence.rb', line 16

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#[]=(key, value) ⇒ Object



26
27
28
29
# File 'lib/omnitest/skeptic/evidence.rb', line 26

def []=(key, value)
  super
  save if autosave?
end

#autosave?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/omnitest/skeptic/evidence.rb', line 31

def autosave?
  @autosave == true
end

#clearObject



51
52
53
54
# File 'lib/omnitest/skeptic/evidence.rb', line 51

def clear
  @store = nil
  file.delete
end

#initialize(file, initial_data = {}) ⇒ Object



20
21
22
23
24
# File 'lib/omnitest/skeptic/evidence.rb', line 20

def initialize(file, initial_data = {})
  @file = Pathname(file)
  FileUtils.mkdir_p(@file.dirname)
  super initial_data
end

#reloadObject



35
36
37
38
39
40
41
# File 'lib/omnitest/skeptic/evidence.rb', line 35

def reload
  store.transaction do
    store.roots.each do | key |
      self[key] = store[key]
    end
  end
end

#saveObject



43
44
45
46
47
48
49
# File 'lib/omnitest/skeptic/evidence.rb', line 43

def save
  store.transaction do
    keys.each do | key |
      store[key] = self[key]
    end
  end
end