class Excursion::Datastores::File
Public Class Methods
new(path)
click to toggle source
# File lib/excursion/datastores/file.rb, line 35 def initialize(path) raise DatastoreConfigurationError if path.nil? || path.to_s.empty? @path = ::File.expand_path(path) rescue raise DatastoreConfigurationError, "Could not initialize the :file datastore with path: '#{path}'" end
Public Instance Methods
all()
click to toggle source
# File lib/excursion/datastores/file.rb, line 29 def all HashWithIndifferentAccess.new(read_file) end
delete(key)
click to toggle source
# File lib/excursion/datastores/file.rb, line 21 def delete(key) current = read_file deleted = current.delete(key.to_s) write_file(current) deleted end
Also aliased as: unset
read(key)
click to toggle source
# File lib/excursion/datastores/file.rb, line 8 def read(key) read_file[key.to_s] end
Also aliased as: get
write(key, value)
click to toggle source
# File lib/excursion/datastores/file.rb, line 13 def write(key, value) current = read_file current[key.to_s] = value write_file(current) current[key.to_s] end
Also aliased as: set
Protected Instance Methods
exists?()
click to toggle source
# File lib/excursion/datastores/file.rb, line 42 def exists? ::File.exists?(@path) end
read_file()
click to toggle source
# File lib/excursion/datastores/file.rb, line 46 def read_file exists? ? YAML.load_file(@path) : {} rescue {} end
write_file(results)
click to toggle source
# File lib/excursion/datastores/file.rb, line 52 def write_file(results) FileUtils.mkpath(::File.dirname(@path)) ::File.open(@path, 'w') { |f| f.write(results.to_yaml)} rescue StandardError => e raise DatastoreConfigurationError, "Could not write to the excursion route pool file: #{@path}" end