Sha256: a3c03abe6542fe9a07ca018612a1bf59c0f3f1d22caaec650d387c3035b8fec8

Contents?: true

Size: 480 Bytes

Versions: 3

Compression:

Stored size: 480 Bytes

Contents

# frozen_string_literal: true
module Codebreaker
  module Storage
    FILE_PATH = 'lib/data/data.yml'

    def save(data)
      create_storage unless storage_exist?
      File.open(FILE_PATH, 'w') { |file| file.write data.to_yaml }
    end

    def restore_storage
      storage_exist? ? YAML.load(File.open(FILE_PATH)) : []
    end

    private

    def storage_exist?
      File.exist? FILE_PATH
    end

    def create_storage
      File.new(FILE_PATH, 'w+')
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
codebreaker_kolyanjy-0.1.8 lib/modules/storage.rb
codebreaker_kolyanjy-0.1.7 lib/modules/storage.rb
codebreaker_kolyanjy-0.1.4 lib/modules/storage.rb