Class: Rbcli::State::LocalStorage
Defined Under Namespace
Classes: LocalStateError
Instance Method Summary
collapse
#[], #[]=, #clear, #commit, #delete, #disconnect, #each, #initialize, #key?, #rbclidata, #refresh, #set_rbclidata, #to_h, #to_s
Instance Method Details
#create_state ⇒ Object
33
34
35
36
37
38
39
40
|
# File 'lib/rbcli/stateful_systems/storagetypes/localstate.rb', line 33
def create_state
begin
FileUtils.mkdir_p File.dirname(@path)
FileUtils.touch @path
rescue Errno::EACCES => e
error "Can not create file #{@path}. Please make sure the directory is writeable." if @halt_on_error
end
end
|
#error(text) ⇒ Object
58
59
60
|
# File 'lib/rbcli/stateful_systems/storagetypes/localstate.rb', line 58
def error text
raise LocalStateError.new "Error accessing local state: #{text}"
end
|
#load_state ⇒ Object
42
43
44
45
46
47
48
|
# File 'lib/rbcli/stateful_systems/storagetypes/localstate.rb', line 42
def load_state
begin
@data = JSON.parse(File.read(@path)).deep_symbolize!
rescue Errno::ENOENT, Errno::EACCES => e
error "Can not read from file #{@path}. Please make sure the file exists and is readable." if @halt_on_error
end
end
|
#save_state ⇒ Object
50
51
52
53
54
55
56
|
# File 'lib/rbcli/stateful_systems/storagetypes/localstate.rb', line 50
def save_state
begin
File.write @path, JSON.dump(@data)
rescue Errno::ENOENT, Errno::EACCES => e
error "Can not write to file #{@path}. Please make sure the file exists and is writeable." if @halt_on_error
end
end
|
#state_exists? ⇒ Boolean
29
30
31
|
# File 'lib/rbcli/stateful_systems/storagetypes/localstate.rb', line 29
def state_exists?
File.exists? @path
end
|
#state_subsystem_init ⇒ Object
25
26
27
|
# File 'lib/rbcli/stateful_systems/storagetypes/localstate.rb', line 25
def state_subsystem_init
@path = File.expand_path @path
end
|