Sha256: e41251889e708321ca3b9ea5eab14ab19545d8986c0ff9fc9d33dd53328f04c5

Contents?: true

Size: 814 Bytes

Versions: 1

Compression:

Stored size: 814 Bytes

Contents

require "save_me/version"
require "path_generator"
require "json"

class SaveMe
  attr_reader :filepath, :new_filepath, :params

  def self.call(filepath, results_path: "./", ymd: 0b111, params: nil)
    new(filepath, results_path, ymd, params).call
  end

  def initialize(filepath, results_path, ymd, params)
    @filepath = filepath
    @new_filepath = PathGenerator.call(filepath, results_path, ymd)
    @params = params
  end

  def call
    create_dir
    copy_file
    save_params
  end

  private

  def create_dir
    FileUtils.mkdir_p(new_filepath)
  end

  def copy_file
    FileUtils.cp(filepath, new_filepath)
  end

  def save_params
    return nil unless params
    params_path = "#{new_filepath}/params.json"
    File.open(params_path, "w") do |file|
      file << params.to_json
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
save_me-1.0.0 lib/save_me.rb