Sha256: 09a89a2b3e120658a61f84231e83a8cf7c088936351c17615516dd2b879ab913

Contents?: true

Size: 357 Bytes

Versions: 4

Compression:

Stored size: 357 Bytes

Contents

module Codebreaker
  class StatsStorage
    PATH = './db/data.yml'.freeze

    def load
      File.file?(PATH) ? YAML.load_file(PATH) : []
    end

    def add(stat)
      stats = load
      stats << stat
      save(stats)
    end

    private

    def save(stats)
      Pathname(PATH).dirname.mkpath
      File.write(PATH, stats.to_yaml)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cb-core-0.1.10 lib/codebreaker/stats_storage.rb
cb-core-0.1.9 lib/codebreaker/stats_storage.rb
cb-core-0.1.8 lib/codebreaker/stats_storage.rb
cb-core-0.1.7 lib/codebreaker/stats_storage.rb