class ConfigFor::Config
@api private
Constants
- CONFIG_CLASS
Public Class Methods
empty()
click to toggle source
# File lib/config_for/config.rb, line 25 def self.empty CONFIG_CLASS.new end
new(path, name)
click to toggle source
# File lib/config_for/config.rb, line 18 def initialize(path, name) @path = path @name = name @monitor = Monitor.new @pathname = Pathname("#{name}.yml").expand_path(path) end
Public Instance Methods
environments()
click to toggle source
# File lib/config_for/config.rb, line 29 def environments config.keys end
fetch(key, &block)
click to toggle source
# File lib/config_for/config.rb, line 33 def fetch(key, &block) config.fetch(key, &block) rescue KeyError raise ConfigFor::MissingEnvironmentError, "#{@pathname} contains just #{environments}, not #{key}" end
Private Instance Methods
config()
click to toggle source
# File lib/config_for/config.rb, line 41 def config @monitor.synchronize do if instance_variable_defined?(:@config) @config else @config = convert(parse) end end end
convert(hash)
click to toggle source
# File lib/config_for/config.rb, line 51 def convert(hash) CONFIG_CLASS.new(hash) end
parse()
click to toggle source
# File lib/config_for/config.rb, line 61 def parse content = read erb = ::ERB.new(content) erb.filename = @pathname.to_s ::YAML.load(erb.result, @pathname) rescue ::Psych::SyntaxError => e fail ConfigFor::InvalidConfigError, "YAML syntax error occurred while parsing #{content}. Error: #{e.message}" end
read()
click to toggle source
# File lib/config_for/config.rb, line 55 def read @pathname.read rescue => error raise ConfigFor::ReadError, error.message end