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
45
46
47
48
49
50
51
52
|
# File 'lib/rbcli/state_storage/localstate.rb', line 45
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
70
71
72
|
# File 'lib/rbcli/state_storage/localstate.rb', line 70
def error text
raise LocalStateError.new "Error accessing local state: #{text}"
end
|
#load_state ⇒ Object
54
55
56
57
58
59
60
|
# File 'lib/rbcli/state_storage/localstate.rb', line 54
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
62
63
64
65
66
67
68
|
# File 'lib/rbcli/state_storage/localstate.rb', line 62
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
41
42
43
|
# File 'lib/rbcli/state_storage/localstate.rb', line 41
def state_exists?
File.exists? @path
end
|
#state_subsystem_init ⇒ Object
37
38
39
|
# File 'lib/rbcli/state_storage/localstate.rb', line 37
def state_subsystem_init
@path = File.expand_path @path
end
|