lib/codebreaker/loader.rb in codebreaker_kub-0.2.5 vs lib/codebreaker/loader.rb in codebreaker_kub-0.2.6
- old
+ new
@@ -1,22 +1,25 @@
# frozen_string_literal: true
module Codebreaker
module Loader
- PATH = File.join(File.dirname(__FILE__), 'data/').freeze
+ # PATH = File.expand_path("../lib/data/#{file_name}", __FILE__)
+ # PATH = File.join(File.dirname(__FILE__), 'data/').freeze
EXTENCTION = '.yml'
def self.load(file_name)
- file_name = PATH + file_name + EXTENCTION.to_s
+ path = File.expand_path("./data/#{file_name}", __dir__)
+ file_name = path + EXTENCTION.to_s
if File.exist?(file_name)
YAML.load_file(file_name)
else
File.new(file_name, 'w')
[]
end
end
def self.save(obj, file_name)
- file_name = PATH + file_name + EXTENCTION.to_s
+ path = File.expand_path("./data/#{file_name}", __dir__)
+ file_name = path + EXTENCTION.to_s
stats = File.file?(file_name) && !File.zero?(file_name) ? YAML.load_file(file_name) : []
stats << obj
file = File.open(file_name, 'w')
file.write(stats.to_yaml)
file.close