class AppConfig::Storage::YAML

YAML storage method.

Constants

DEFAULT_PATH

Public Class Methods

new(path = DEFAULT_PATH, options = {}) click to toggle source

Loads `@data` with the YAML file located at `path`. `@data` will be the OpenStruct that is accessed with `AppConfig.some_var`.

Defaults to `Dir.home/.app_config.yml`

# File lib/app_config/storage/yaml.rb, line 15
def initialize(path = DEFAULT_PATH, options = {})
  # Allow passing `true` as an option to use `DEFAULT_PATH`.
  @path = path.is_a?(TrueClass) ? DEFAULT_PATH : path
  @options = options
  reload!
end

Public Instance Methods

reload!() click to toggle source
# File lib/app_config/storage/yaml.rb, line 22
def reload!
  # Make sure to use the top-level YAML module here.
  if @options.has_key?(:env)
    env = @options[:env].to_s  # Force a String here since YAML's keys are strings.
    @data = Storage::ConfigData.new(::YAML.load_file(@path)[env])
  else
    @data = Storage::ConfigData.new(::YAML.load_file(@path))
  end
end