Class: Kozo::Backends::Local
Direct Known Subclasses
Git
Instance Attribute Summary collapse
#configuration, #directory
Instance Method Summary
collapse
#==, #state, #state=
Constructor Details
#initialize(configuration, directory) ⇒ Local
Returns a new instance of Local.
13
14
15
16
17
|
# File 'lib/kozo/backends/local.rb', line 13
def initialize(configuration, directory)
super
@directory ||= Kozo.options.directory
end
|
Instance Attribute Details
#backups ⇒ Object
Returns the value of attribute backups.
10
11
12
|
# File 'lib/kozo/backends/local.rb', line 10
def backups
@backups
end
|
#file ⇒ Object
59
60
61
|
# File 'lib/kozo/backends/local.rb', line 59
def file
@file ||= "kozo.kzstate"
end
|
#fingerprint ⇒ Object
Returns the value of attribute fingerprint.
11
12
13
|
# File 'lib/kozo/backends/local.rb', line 11
def fingerprint
@fingerprint
end
|
Instance Method Details
#data ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/kozo/backends/local.rb', line 28
def data
Kozo.logger.debug "Reading local state in #{path}"
YAML
.safe_load(File.read(path), permitted_classes: [Time, Date])
.deep_symbolize_keys
rescue Errno::ENOENT, Errno::ENOTDIR
raise StateError, "local state at #{path} not initialized"
rescue Psych::SyntaxError => e
raise StateError, "could not read state file: #{e.message}"
end
|
#data=(value) ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/kozo/backends/local.rb', line 40
def data=(value)
Kozo.logger.debug "Writing local state in #{path}"
return if @data.hash == value.hash
@data = value
return if Kozo.options.dry_run?
File.write("#{path}.tmp", value.deep_stringify_keys.to_yaml)
FileUtils.mv(path, "#{path}.#{DateTime.current.to_i}.kzbackup") if backups && File.exist?(path)
FileUtils.mv("#{path}.tmp", path)
end
|
#initialize! ⇒ Object
19
20
21
22
23
24
25
26
|
# File 'lib/kozo/backends/local.rb', line 19
def initialize!
Kozo.logger.debug "Initializing local state in #{path}"
return if File.exist?(path)
self.state = State.new
end
|
#path ⇒ Object
63
64
65
|
# File 'lib/kozo/backends/local.rb', line 63
def path
@path ||= File.join(directory, file)
end
|