Sha256: 2610ecbd9ba1dfcd74b2e7f6f77ebf0258932d884d9d6b74a67b94a7516af1c0

Contents?: true

Size: 623 Bytes

Versions: 2

Compression:

Stored size: 623 Bytes

Contents

# frozen_string_literal: true

module Codebreaker
  class SaveRes
    include Validation

    FILE_PATH = "#{ENV["DB_PATH"]}#{ENV["DB_FILE"]}"

    def initialize(db_file_path = FILE_PATH)
      @db_file_path = db_file_path
    end

    def load
      validate_file_existens(FILE_PATH)

      File.open(FILE_PATH, "r") do |file|
        YAML.load_stream(file)
      end
    end

    def save(object)
      create_directory("DB_PATH") unless Dir.exist?(ENV["DB_PATH"])
      File.open(FILE_PATH, "a") { |file| file.write(object.to_yaml) }
    end

    def create_directory(path)
      Dir.mkdir(ENV[path])
    end
  end
end

Version data entries

2 entries across 1 versions & 1 rubygems

Version Path
codebreaker_manfly-0.1.0 lib/codebreaker/module/save_res.rb
codebreaker_manfly-0.1.0 lib/codebreaker/save_res.rb