Class: Rematch

Inherits:
Object
  • Object
show all
Defined in:
lib/rematch.rb

Overview

Implement the key/value store

Constant Summary collapse

VERSION =
'1.3.0'
EXT =
'.rematch'

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:, id:) ⇒ Rematch

path and unique id of the test being run



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

def initialize(path:, id:)
  path = "#{path}#{EXT}"
  self.class.check_rebuild(path)
  @store = YAML::Store.new(path, true)
  @id    = id
  @count = 0
end

Class Attribute Details

.rebuildObject

Returns the value of attribute rebuild.



13
14
15
# File 'lib/rematch.rb', line 13

def rebuild
  @rebuild
end

Class Method Details

.check_rebuild(path) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/rematch.rb', line 15

def check_rebuild(path)
  return unless @rebuild && !@rebuilt.include?(path)

  FileUtils.rm_f(path)
  @rebuilt << path
  puts "Rebuilt #{path}"
end

Instance Method Details

#rematch(value) ⇒ Object

store if unknown; retrieve otherwise



34
35
36
37
# File 'lib/rematch.rb', line 34

def rematch(value)
  key = "[#{@count += 1}] #{@id}"
  @store.transaction { |s| s.root?(key) ? s[key] : s[key] = value }
end