Sha256: 538f88a4bcab2cec3e1fe01721cb2f8446f81537d735217f4db897455c92608c
Contents?: true
Size: 1.33 KB
Versions: 1
Compression:
Stored size: 1.33 KB
Contents
module Enviro module Configuration class FileNotFound < StandardError; end class UnknownEnvironment < StandardError; end def self.included(base) base.send(:extend, ClassMethods) end module ClassMethods def configuration_path_env(value=nil) @_configuration_path_env ||= 'ENVY_CONF_PATH' @_configuration_path_env = value.to_s.upcase unless value.nil? @_configuration_path_env end def configuration_path_str(path=nil) @_configuration_path_str = path end def configuration_path if @_configuration_path_str @_configuration_path ||= @_configuration_path_str else @_configuration_path ||= (ENV[configuration_path_env]||'enviro.yml') end end def configuration @_configuration ||= _load_configuration_path end private def _load_configuration_path raise FileNotFound.new(self.configuration_path) unless File.exists?(self.configuration_path) @raw_configuration = YAML.load_file(self.configuration_path) raise UnknownEnvironment.new(self.environment) unless @raw_configuration.key?(self.environment) OpenStruct.new(@raw_configuration[self.environment].merge(:environment => self.environment)) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
enviro-0.0.4 | lib/enviro/configuration.rb |