Module: Konfa::Initializer::ClassMethods
- Defined in:
- lib/konfa/initializer.rb
Instance Method Summary collapse
Instance Method Details
#init_with_env ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/konfa/initializer.rb', line 27 def init_with_env conf_prefix = self.env_variable_prefix.upcase ENV.keys.reject { |key| key !~ /^#{conf_prefix}/ # Ignore everything that doesn't match the prefix }.each { |key| variable = key[conf_prefix.size..-1].downcase self.store(variable, ENV[key]) } dump end |
#init_with_yaml(path) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/konfa/initializer.rb', line 10 def init_with_yaml(path) # FIXME: It would be a lot cleaner if the YAML library would raise an # exception if it fails to read the file. We'll handle it like this for now # load_file just returns "false" if it fails yaml_data = YAML.load_file(path) unless yaml_data.nil? raise Konfa::InitializationError.new("Bad YAML format, key/value pairs expected") unless yaml_data.kind_of?(Hash) yaml_data.each do |variable, value| self.store(variable, value) end end dump end |