module Simplepub::Configuration

Attributes

config[R]

Public Instance Methods

configure() { |config| ... } click to toggle source
# File lib/simplepub/configuration.rb, line 8
def configure(&block)
  yield(config)
end
default_config_file() click to toggle source
# File lib/simplepub/configuration.rb, line 17
def default_config_file
  return config.config_file if config.config_file?
  config_file = config_file_paths.detect { |path| File.exists?(path) }
  config_file
end
default_environment() click to toggle source
# File lib/simplepub/configuration.rb, line 23
def default_environment
  config.environment? ? config.environment : "development"
end
load_config(filename=default_config_file, environment=default_environment) click to toggle source

Loads the configuration from a given YAML file and environment (such as production)

# File lib/simplepub/configuration.rb, line 28
def load_config(filename=default_config_file, environment=default_environment)
  raise ConfigurationFileError, "Configuration file not found. Available paths: #{config_file_paths.inspect}" if filename.nil?

  yaml = YAML.load_file(filename)[environment.to_s]

  raise ArgumentError, "The #{environment} environment does not exist in #{filename}" if yaml.nil?

  config.deep_merge!(yaml)
end
reset_config() click to toggle source

Resets the configuration to the default (empty hash)

# File lib/simplepub/configuration.rb, line 13
def reset_config
  @config = Hashie::Mash.new
end

Private Instance Methods

config_file_paths() click to toggle source
# File lib/simplepub/configuration.rb, line 40
def config_file_paths
  [
    "#{ENV['HOME']}/.simplepub.yml",
    "/etc/simplepub/config.yml",
    "/etc/simplepub.yml"
  ]
end