class Cookbooks::SimpleConfigurationLoader

Public Class Methods

[](i = '') click to toggle source
#

[]

#
# File lib/cookbooks/configuration/simple_configuration_loader.rb, line 89
def self.[](i = '')
  self.new(i)
end
new( i = nil, run_already = true ) click to toggle source
#

initialize

#
# File lib/cookbooks/configuration/simple_configuration_loader.rb, line 26
def initialize(
    i           = nil,
    run_already = true
  )
  reset
  run if run_already
end

Public Instance Methods

iterate_over_the_yaml_files() click to toggle source
#

#iterate_over_the_yaml_files

#
# File lib/cookbooks/configuration/simple_configuration_loader.rb, line 56
def iterate_over_the_yaml_files
  _ = @yaml_files
  unless _.empty?
    _.each {|this_yaml_file|
      name_of_the_method_that_is_to_be_defined = File.basename(
        this_yaml_file.sub(/\.yml$/,'')
      ).to_sym
      # =================================================================== #
      # Register which automatically defined methods will be available.
      # These can then be used e. g. .use_colours()
      # =================================================================== #
      @array_available_methods << name_of_the_method_that_is_to_be_defined
      data = YAML.load_file(this_yaml_file)
      self.class.class_eval {
        define_method(name_of_the_method_that_is_to_be_defined) {
          data
        }
      }
    }
  end
end
obtain_all_available_yaml_files( from_this_dir = CONFIGURATION_DIRECTORY ) click to toggle source
#

#obtain_all_available_yaml_files

This method will fetch every available .yml file that is part of the “configuration system” for the Cookbooks.

#
# File lib/cookbooks/configuration/simple_configuration_loader.rb, line 47
def obtain_all_available_yaml_files(
    from_this_dir = CONFIGURATION_DIRECTORY
  )
  @yaml_files = Dir["#{from_this_dir}*.yml"]
end
reset() click to toggle source
#

reset (reset tag)

#
# File lib/cookbooks/configuration/simple_configuration_loader.rb, line 37
def reset
  @array_available_methods = []
end
run() click to toggle source
#

run (run tag)

#
# File lib/cookbooks/configuration/simple_configuration_loader.rb, line 81
def run
  obtain_all_available_yaml_files
  iterate_over_the_yaml_files
end