class RBT::Configuration::SimpleConfigurationLoader

Public Class Methods

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

RBT::SimpleConfigurationLoader[]

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

initialize

#
# File lib/rbt/configuration/simple_configuration_loader.rb, line 38
def initialize(
    run_already = true
  )
  reset
  run if run_already
end
return_value_of_this_configuration_value(i) click to toggle source
#

RBT::SimpleConfigurationLoader.return_value_of_this_configuration_value

This method could be used to quickly return the value of a particular configuration value, if you know the name of its associated yaml file.

Invocation example:

x = RBT::Configuration::SimpleConfigurationLoader.return_value_of_this_configuration_value('use_abbreviations')
#
# File lib/rbt/configuration/simple_configuration_loader.rb, line 214
def self.return_value_of_this_configuration_value(i)
  i = i.to_sym unless i.is_a? Symbol
  result = nil
  _ = RBT::Configuration::SimpleConfigurationLoader.new
  result = _.send(i)
  return result
end

Public Instance Methods

array_available_methods?() click to toggle source
#

array_available_methods?

#
# File lib/rbt/configuration/simple_configuration_loader.rb, line 61
def array_available_methods?
  @array_available_methods
end
do_save( these_files = @yaml_files ) click to toggle source
#

do_save

#
# File lib/rbt/configuration/simple_configuration_loader.rb, line 161
def do_save(
    these_files = @yaml_files
  )
  sorted = these_files.sort
  sorted.each {|this_yaml_file|
    # ===================================================================== #
    # The variable `this_yaml_file` may look like so:
    #
    #   /home/Programs/Ruby/2.7.2/lib/ruby/site_ruby/2.7.0/rbt/yaml/configuration/cookbook_directory.yml
    #
    # ===================================================================== #
    method_name = File.basename(this_yaml_file).sub(/\.yml$/,'')
    new_value = send(method_name)
    ::RBT.write_what_into(new_value, this_yaml_file)
    # ===================================================================== #
    # We also have to store into my home directory, if we are on a
    # roebe system.
    # ===================================================================== #
    if ::RBT.is_on_roebe?
      into = ::RBT::RUBY_SRC_DIR_RBT_YAML+'configuration/'+
             File.basename(this_yaml_file)
      ::RBT.write_what_into(new_value, into)
    end
  }
end
iterate_over_the_yaml_files() click to toggle source
#

iterate_over_the_yaml_files

#
# File lib/rbt/configuration/simple_configuration_loader.rb, line 80
def iterate_over_the_yaml_files
  _ = @yaml_files.sort
  # ======================================================================= #
  # Batch-load all .yml files next, that reside under rbt/configuration/.
  # The respective files are, for example, "email.yml" and so forth.
  # ======================================================================= #
  unless _.empty?
    _.each {|this_yaml_file|
      # =================================================================== #
      # Load up the data from this yaml file first.
      # =================================================================== #
      data = YAML.load_file(this_yaml_file)
      name_of_the_method_that_is_to_be_defined = File.basename(
        this_yaml_file.sub(/\.yml$/,'') # We don't need the .yml part afterwards.
      ).to_sym
      # =================================================================== #
      # Register which automatically defined methods will be available.
      # =================================================================== #
      @array_available_methods << name_of_the_method_that_is_to_be_defined
      # =================================================================== #
      # Next, sanitize Boolean values here.
      # =================================================================== #
      if data.is_a? String
        if data.include? '$'
          # =============================================================== #
          # Obtain the value of that particular environment setting next.
          # =============================================================== #
          data = RBT.convert_global_env(data).dup
          if File.directory?(data) and !data.end_with?('/')
            data << '/' # Directories will have a trailing '/' character.
          end
        end
        # ================================================================= #
        # Sanitize the data-entry towards a boolean value, if it is either
        # "f" or "t".
        # ================================================================= #
        case data
        when 'f'
          data = false
        when 't'
          data = true
        end
      end
      # =================================================================== #
      # Define setters - these will have a trailing '=' character.
      # =================================================================== #
      this_method_setter = (
        "#{name_of_the_method_that_is_to_be_defined}="
      ).to_sym
      # =================================================================== #
      # Add these setters to the array that registered these
      # methods.
      # =================================================================== #
      unless @array_available_methods.include? this_method_setter
        @array_available_methods << this_method_setter
      end
      self.class.class_eval {
        # ================================================================= #
        # Also set a corresponding instance variable.
        # ================================================================= #
        instance_variable_set(
          ('@'+name_of_the_method_that_is_to_be_defined.to_s).to_sym, data
        )
        define_method(name_of_the_method_that_is_to_be_defined.to_sym) {
          self.class.class_eval {
            instance_variable_get(('@'+name_of_the_method_that_is_to_be_defined.to_s).to_sym)
          }
        }
        define_method(this_method_setter) {|input_argument|
          self.class.class_eval {
            instance_variable_set(('@'+name_of_the_method_that_is_to_be_defined.to_s).to_sym, input_argument)
          }
        }
      }
    }
  end
end
obtain_all_available_yaml_files( from_this_dir = ::RBT.rbt_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 RBT.

#
# File lib/rbt/configuration/simple_configuration_loader.rb, line 71
def obtain_all_available_yaml_files(
    from_this_dir = ::RBT.rbt_configuration_directory?
  )
  @yaml_files = Dir["#{from_this_dir}*.yml"]
end
reset() click to toggle source
#

reset (reset tag)

#
# File lib/rbt/configuration/simple_configuration_loader.rb, line 48
def reset
  # ======================================================================= #
  # === @array_available_methods
  #
  # The Array @array_available_methods will determine which methods
  # are available on this class.
  # ======================================================================= #
  @array_available_methods = []
end
run() click to toggle source
#

run (run tag)

#
# File lib/rbt/configuration/simple_configuration_loader.rb, line 190
def run
  obtain_all_available_yaml_files
  iterate_over_the_yaml_files
end