Class: RBT::Configuration::SimpleConfigurationLoader
- Inherits:
-
Object
- Object
- RBT::Configuration::SimpleConfigurationLoader
- Defined in:
- lib/rbt/configuration/simple_configuration_loader.rb
Overview
RBT::Configuration::SimpleConfigurationLoader
Class Method Summary collapse
-
.[](i = '') ⇒ Object
# === RBT::SimpleConfigurationLoader[] ========================================================================= #.
-
.return_value_of_this_configuration_value(i) ⇒ Object
# === RBT::SimpleConfigurationLoader.return_value_of_this_configuration_value.
Instance Method Summary collapse
-
#array_available_methods? ⇒ Boolean
(also: #hash?, #_, #_?, #available_methods?)
# === array_available_methods? ========================================================================= #.
-
#do_save(these_files = @yaml_files) ⇒ Object
# === do_save ========================================================================= #.
-
#initialize(run_already = true) ⇒ SimpleConfigurationLoader
constructor
# === initialize ========================================================================= #.
-
#iterate_over_the_yaml_files ⇒ Object
# === iterate_over_the_yaml_files ========================================================================= #.
-
#obtain_all_available_yaml_files(from_this_dir = ::RBT.rbt_configuration_directory?) ⇒ Object
# === obtain_all_available_yaml_files.
-
#reset ⇒ Object
# === reset (reset tag) ========================================================================= #.
-
#run ⇒ Object
# === run (run tag) ========================================================================= #.
Constructor Details
#initialize(run_already = true) ⇒ SimpleConfigurationLoader
#
initialize
#
38 39 40 41 42 43 |
# File 'lib/rbt/configuration/simple_configuration_loader.rb', line 38 def initialize( run_already = true ) reset run if run_already end |
Class Method Details
.[](i = '') ⇒ Object
#
RBT::SimpleConfigurationLoader[]
#
204 205 206 |
# File 'lib/rbt/configuration/simple_configuration_loader.rb', line 204 def self.[](i = '') new(i) end |
.return_value_of_this_configuration_value(i) ⇒ Object
#
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')
#
220 221 222 223 224 225 226 |
# File 'lib/rbt/configuration/simple_configuration_loader.rb', line 220 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 |
Instance Method Details
#array_available_methods? ⇒ Boolean Also known as: hash?, _, _?, available_methods?
#
array_available_methods?
#
61 62 63 |
# File 'lib/rbt/configuration/simple_configuration_loader.rb', line 61 def array_available_methods? @array_available_methods end |
#do_save(these_files = @yaml_files) ⇒ Object
#
do_save
#
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/rbt/configuration/simple_configuration_loader.rb', line 167 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 ⇒ Object
#
iterate_over_the_yaml_files
#
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/rbt/configuration/simple_configuration_loader.rb', line 83 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?) ⇒ Object
#
obtain_all_available_yaml_files
This method will fetch every available .yml file that is part of the “configuration system” for the RBT.
#
74 75 76 77 78 |
# File 'lib/rbt/configuration/simple_configuration_loader.rb', line 74 def obtain_all_available_yaml_files( from_this_dir = ::RBT.rbt_configuration_directory? ) @yaml_files = Dir["#{from_this_dir}*.yml"] end |
#reset ⇒ Object
#
reset (reset tag)
#
48 49 50 51 52 53 54 55 56 |
# 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 ⇒ Object
#
run (run tag)
#
196 197 198 199 |
# File 'lib/rbt/configuration/simple_configuration_loader.rb', line 196 def run obtain_all_available_yaml_files iterate_over_the_yaml_files end |