Sha256: 5e836bd95ed0d220cfebeb9f582b5536be7df614482e9bbb26dc9c2762d1decf

Contents?: true

Size: 648 Bytes

Versions: 3

Compression:

Stored size: 648 Bytes

Contents

require 'yaml'

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

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

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

  private

  def self.config
    create_config_file_if_not_exists!

    YAML.load_file(CONFIG_FILE_PATH)
  end

  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

3 entries across 3 versions & 1 rubygems

Version Path
fuck_facebook-0.4.1 src/config.rb
fuck_facebook-0.4.0 src/config.rb
fuck_facebook-0.3.0 src/config.rb