Sha256: bc627039e6a41866b45eefd115e8723ecaf7a8cc5fd4a8b6f576ba5fbad61e5c

Contents?: true

Size: 680 Bytes

Versions: 5

Compression:

Stored size: 680 Bytes

Contents

# frozen_string_literal: true

module Codebreaker
  module Loader
    PATH = File.join(File.dirname(__FILE__), 'data/').freeze
    EXTENCTION = '.yml'
    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.2.5 lib/codebreaker/loader.rb
codebreaker_kub-0.2.4 lib/codebreaker/loader.rb
codebreaker_kub-0.2.3 lib/codebreaker/loader.rb
codebreaker_kub-0.2.2 lib/codebreaker/loader.rb
codebreaker_kub-0.2.1 lib/codebreaker/loader.rb