class SSC::DirectoryManager::LocalStorageFile
Public Class Methods
new(file_name, path= nil)
click to toggle source
# File lib/directory_manager.rb, line 5 def initialize(file_name, path= nil) path = path ? path : Dir.pwd @location= File.join(path, file_name) end
Public Instance Methods
[](section)
click to toggle source
# File lib/directory_manager.rb, line 19 def [](section) read if @parsed_file[section] @parsed_file[section] else [] end end
empty_list?()
click to toggle source
# File lib/directory_manager.rb, line 55 def empty_list? read (!@parsed_file['list']) || (@parsed_file['list'] == []) || (@parsed_file['list'] == {}) end
pop(section)
click to toggle source
# File lib/directory_manager.rb, line 28 def pop(section) read if @parsed_file[section].is_a?(Array) @parsed_file[section].pop else nil end end
push(section, item)
click to toggle source
# File lib/directory_manager.rb, line 37 def push(section, item) read if @parsed_file[section].is_a?(Array) @parsed_file[section] |= [ item ] else @parsed_file[section] = [ item ] end item end
read()
click to toggle source
# File lib/directory_manager.rb, line 14 def read # default error is informative enough if the file is not found @parsed_file = @parsed_file || YAML::load(File.read(@location)) || {} end
save()
click to toggle source
# File lib/directory_manager.rb, line 48 def save contents= @parsed_file.to_yaml @parsed_file= nil File.open(@location, 'w') {|f| f.write contents} contents end
valid?()
click to toggle source
# File lib/directory_manager.rb, line 10 def valid? File.exist?(@location) end