Class: GroongaDelta::Status

Inherits:
Object
  • Object
show all
Defined in:
lib/groonga-delta/status.rb

Direct Known Subclasses

ApplyStatus, ImportStatus

Instance Method Summary collapse

Constructor Details

#initialize(dir) ⇒ Status

Returns a new instance of Status.



21
22
23
24
25
26
27
28
29
# File 'lib/groonga-delta/status.rb', line 21

def initialize(dir)
  @dir = dir
  @path = File.join(@dir, "status.yaml")
  if File.exist?(@path)
    @data = YAML.load(File.read(@path))
  else
    @data = {}
  end
end

Instance Method Details

#[](key) ⇒ Object



31
32
33
# File 'lib/groonga-delta/status.rb', line 31

def [](key)
  @data[key]
end

#update(data) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/groonga-delta/status.rb', line 35

def update(data)
  @data.update(data)
  FileUtils.mkdir_p(@dir)
  path_writing = "#{@path}.writing"
  File.open(path_writing, "w") do |output|
    output.puts(YAML.dump(@data))
  end
  FileUtils.mv(path_writing, @path)
end