Sha256: 9e58a6f0b0fea55eb0614b16ab50792cdc57c90b4615502d4c37c27ed013f688

Contents?: true

Size: 656 Bytes

Versions: 5

Compression:

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
codebreaker_kub-0.1.9 lib/codebreaker/loader.rb
codebreaker_kub-0.1.6 lib/codebreaker/loader.rb
codebreaker_kub-0.1.5 lib/codebreaker/loader.rb
codebreaker_kub-0.1.4 lib/codebreaker/loader.rb
codebreaker_kub-0.1.3 lib/codebreaker/loader.rb