Class: BuildpackSupport::ConfigurationUtils

Inherits:
Object
  • Object
show all
Includes:
DirectoryFinder
Defined in:
lib/buildpack_support/configuration_utils.rb

Overview

Utilities for dealing with Configuration files

Instance Method Summary collapse

Methods included from DirectoryFinder

#load_path_peer

Constructor Details

#initialize(should_log = true) ⇒ ConfigurationUtils

Creates a new instance

Parameters:

  • should_log (Boolean) (defaults to: true)

    whether the contents of the configuration file should be logged. This value should be left to its default and exists to allow the logger to use the utility.



32
33
34
35
# File 'lib/buildpack_support/configuration_utils.rb', line 32

def initialize(should_log = true)
  @config_directory = load_path_peer 'config'
  @logger           = BuildpackSupport::Logging::LoggerFactory.instance.get_logger ConfigurationUtils if should_log
end

Instance Method Details

#load(identifier) ⇒ Hash

Loads a configuration file from the buildpack configuration directory. If the configuration file does not exist, returns an empty hash.

Parameters:

  • identifier (String)

    the identifier of the configuration

Returns:

  • (Hash)

    the configuration or an empty hash if the configuration file does not exist



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/buildpack_support/configuration_utils.rb', line 42

def load(identifier)
  file = @config_directory + "#{identifier}.yml"

  configuration = {}
  if file.exist?
    configuration = YAML.load_file(file)
    @logger.debug { "Configuration from #{file}: #{configuration}" } if @logger
  else
    @logger.debug { "No configuration file #{file} found" } if @logger
  end

  configuration
end