Sha256: b770cb77244175e001874dac882a0ce065c6ffe7417ce25efb356187b8ad2734

Contents?: true

Size: 720 Bytes

Versions: 1

Compression:

Stored size: 720 Bytes

Contents

require 'yaml'

class Config
  CONFIG_FILE_PATH = "#{ENV['HOME']}/.local/share/fuck-facebook/config.yaml".freeze

  def self.option(*path, default: nil)
    env_var = "FF_#{path.join('_').upcase}"
    return ENV[env_var] if ENV[env_var]

    path_strings = path.map(&:to_s)
    value = config.dig(*path_strings)

    return value if value

    default
  end

  def self.config
    create_config_file_if_not_exists!

    YAML.load_file(CONFIG_FILE_PATH)
  end

  private_class_method def self.create_config_file_if_not_exists!
    dirname = File.dirname(CONFIG_FILE_PATH)
    FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
    File.write(CONFIG_FILE_PATH, '{}') unless File.exist?(CONFIG_FILE_PATH)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fuck_facebook-0.5.0 src/config.rb