Sha256: d790c87ca0a93ce5dfb5854f2cbf391faac79b38219cb2a5dc19fafde78632a6

Contents?: true

Size: 634 Bytes

Versions: 2

Compression:

Stored size: 634 Bytes

Contents

module Codebreaker
  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)
    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) : []
      stats << obj
      file = File.open(file_name, 'w')
      file.write(stats.to_yaml)
      file.close
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
codebreaker_kub-0.1.8 lib/codebreaker/loader.rb
codebreaker_kub-0.1.7 lib/codebreaker/loader.rb