lib/codebreaker/loader.rb in codebreaker_kub-0.1.8 vs lib/codebreaker/loader.rb in codebreaker_kub-0.1.9
- old
+ new
@@ -2,12 +2,15 @@
module Loader
PATH = File.join(File.dirname(__FILE__), 'data/').freeze
EXTENCTION = '.yml'.freeze
def self.load(file_name)
file_name = PATH + file_name + EXTENCTION.to_s
- raise LoadError, 'No such file to load' unless File.exist?(file_name)
-
- YAML.load_file(file_name)
+ 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
stats = File.file?(file_name) && !File.zero?(file_name) ? YAML.load_file(file_name) : []