lib/relaton/db_cache.rb in relaton-0.2.6 vs lib/relaton/db_cache.rb in relaton-0.3.0
- old
+ new
@@ -5,32 +5,32 @@
# @param dir [String] DB directory
def initialize(dir)
@dir = dir
Dir.mkdir @dir unless Dir.exist? @dir
- fiele_version = "#{@dir}/version"
- File.write fiele_version, VERSION unless File.exist? fiele_version
+ file_version = "#{@dir}/version"
+ File.write file_version, VERSION, encoding: "utf-8" unless File.exist? file_version
end
# Save item
# @param key [String]
# @param value [String] Bibitem xml serialization
def []=(key, value)
return if value.nil?
prefix_dir = "#{@dir}/#{prefix(key)}"
Dir.mkdir prefix_dir unless Dir.exist? prefix_dir
- File.write filename(key), value
+ File.write filename(key), value, encoding: "utf-8"
end
# Read item
# @param key [String]
# @return [String]
def [](key)
file = filename key
return unless File.exist? file
- File.read(file)
+ File.read(file, encoding: "utf-8")
end
# Return fetched date
# @param key [String]
# @return [String]
@@ -39,19 +39,19 @@
return unless value
if value =~ /^not_found/
value.match(/\d{4}-\d{2}-\d{2}/).to_s
else
doc = Nokogiri::XML value
- doc.at('/bibitem/fetched').text
+ doc.at('/bibitem/fetched')&.text
end
end
# Returns all items
# @return [Array<Hash>]
def all
Dir.glob("testcache/**/*.xml").sort.map do |f|
- File.read(f)
+ File.read(f, encoding: "utf-8")
end
end
# Delete item
# @param key [String]
@@ -61,17 +61,17 @@
end
# Check if version of the DB match to the gem version.
# @return [TrueClass, FalseClass]
def check_version?
- v = File.read @dir + "/version"
+ v = File.read @dir + "/version", encoding: "utf-8"
v == VERSION
end
# Set version of the DB to the gem version.
# @return [Relaton::DbCache]
def set_version
- File.write @dir + "/version", VERSION
+ File.write @dir + "/version", VERSION, encoding: "utf-8"
self
end
# if cached reference is undated, expire it after 60 days
# @param key [String]