lib/pupa/processor/document_store/file_store.rb in pupa-0.0.11 vs lib/pupa/processor/document_store/file_store.rb in pupa-0.0.12
- old
+ new
@@ -14,11 +14,11 @@
# Returns whether a file with the given name exists.
#
# @param [String] name a key
# @return [Boolean] whether the store contains an entry for the given key
def exist?(name)
- File.exist?(namespaced_key(name))
+ File.exist?(path(name))
end
# Returns all file names in the storage directory.
#
# @return [Array<String>] all keys in the store
@@ -31,12 +31,12 @@
# Returns, as JSON, the contents of the file with the given name.
#
# @param [String] name a key
# @return [Hash] the value of the given key
def read(name)
- File.open(namespaced_key(name)) do |f|
- MultiJson.load(f)
+ File.open(path(name)) do |f|
+ Oj.load(f)
end
end
# Returns, as JSON, the contents of the files with the given names.
#
@@ -51,12 +51,12 @@
# Writes, as JSON, the value to a file with the given name.
#
# @param [String] name a key
# @param [Hash] value a value
def write(name, value)
- File.open(namespaced_key(name), 'w') do |f|
- f.write(MultiJson.dump(value))
+ File.open(path(name), 'w') do |f|
+ f.write(Oj.dump(value, mode: :compat, time_format: :ruby))
end
end
# Writes, as JSON, the value to a file with the given name, unless such
# a file exists.
@@ -81,11 +81,11 @@
# Delete a file with the given name.
#
# @param [String] name a key
def delete(name)
- File.delete(namespaced_key(name))
+ File.delete(path(name))
end
# Deletes all files in the storage directory.
def clear
Dir[File.join(@output_dir, '*.json')].each do |path|
@@ -96,12 +96,14 @@
# Collects commands to run all at once.
def pipelined
yield
end
- private
-
- def namespaced_key(name)
+ # Returns the path to the file with the given name.
+ #
+ # @param [String] name a key
+ # @param [String] a path
+ def path(name)
File.join(@output_dir, name)
end
end
end
end