Class: Vapir::YamlConfiguration

Inherits:
HashConfigurationWithOtherStuff show all
Defined in:
lib/vapir-common/config.rb

Instance Attribute Summary collapse

Attributes inherited from HashConfigurationWithOtherStuff

#key_prefix

Attributes inherited from Configuration

#parent

Instance Method Summary collapse

Methods inherited from HashConfigurationWithOtherStuff

#unprefixed_recognized_key, #update_from_source

Methods inherited from Configuration

#[], #[]=, #create, #create_update, #defined_key?, #delete, #locally_defined_key?, #method_missing, #read, #recognize_key!, #recognized_key?, #recognized_keys, #update, #update_hash, #validate_key_format!, #with_config

Constructor Details

#initialize(parent, yaml_file) ⇒ YamlConfiguration

Returns a new instance of YamlConfiguration.



268
269
270
271
272
# File 'lib/vapir-common/config.rb', line 268

def initialize(parent, yaml_file)
  super(parent)
  @yaml_file=yaml_file
  update_from_source
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Vapir::Configuration

Instance Attribute Details

#yaml_fileObject (readonly)

Returns the value of attribute yaml_file.



267
268
269
# File 'lib/vapir-common/config.rb', line 267

def yaml_file
  @yaml_file
end

Instance Method Details

#config_hashObject



273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# File 'lib/vapir-common/config.rb', line 273

def config_hash
  if yaml_file && File.exists?(yaml_file)
    require 'yaml'
    @loaded_yaml ||= YAML.load_file(yaml_file) # don't want to reload this every time #update_from_source is called 
    if @loaded_yaml.is_a?(Hash)
      @loaded_yaml
    elsif @loaded_yaml == false || @loaded_yaml == nil
      {}
    else
      raise ArgumentError, "Attempted to load Vapir configuration from the YAML file at #{yaml_file.inspect}, but its contents parsed as a #{@loaded_yaml.class}; expected a hash.\nYAML.load_file(#{yaml_file.inspect}) = #{@loaded_yaml.inspect}"
    end
  else
    {}
  end
end