Sha256: 2da32f5d61fcdbc6f5525f9decae85707e685d92ed2f1b33ed25d6f3db26fa41

Contents?: true

Size: 1014 Bytes

Versions: 1

Compression:

Stored size: 1014 Bytes

Contents

require 'singleton'
require 'yaml'
require 'erb'

require "armoire/setting"
require "armoire/version"

if defined?(Rails::Railtie)
  require "armoire/railtie"
elsif defined?(Rails.configuration)
  require "armoire/init"
end

class Armoire
  include Singleton

  attr_accessor :settings

  def environment
    ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
  end

  def self.[](key)
    instance.settings[key]
  end

  def self.load!(path_to_config_file)
    instance.settings = Setting.new(instance.load_settings(path_to_config_file))
  end

  def load_settings(path_to_config_file)
    YAML.load(ERB.new(File.read(path_to_config_file)).result)[environment]
  rescue Errno::ENOENT => e
    raise MissingSettingsFile.new('The settings file cannot be found')
  end

  # When the settings file cannot be read, this exception will be raised
  class MissingSettingsFile < StandardError; end

  # When a config setting isn't set, this exception will be raised
  class ConfigSettingMissing < StandardError; end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
armoire-1.2.1 lib/armoire.rb