Class: Roebe::Configuration::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/roebe/configuration/class/configuration.rb

Overview

Roebe::Configuration::Configuration

Constant Summary collapse

ARRAY_THESE_METHODS_SHALL_NOT_BE_OVERWRITTEN =
#

ARRAY_THESE_METHODS_SHALL_NOT_BE_OVERWRITTEN

#
[
  :be_verbose?
]
NAMESPACE =
#

NAMESPACE

#
inspect
USE_ONLY_SYMBOLS_AS_KEY =
#

USE_ONLY_SYMBOLS_AS_KEY

If true then we use only symbols as keys for the internal hash.

#
true
SHALL_WE_CREATE_MISSING_BASE_DIRECTORY =
#

SHALL_WE_CREATE_MISSING_BASE_DIRECTORY

If true then this class will try to create the base directory if it is missing.

#
false
THIS_FILE =
#

THIS_FILE

#
'configuration.rb'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(commandline_arguments = ARGV, run_already = true) ⇒ Configuration

#

initialize

You do not have to provide any argument to this class. However had, IF an argument has been given, then it will be assumed to be the path to the directory that keeps all the .yml files that class Configuration will batch-read (“slurp up”).

#


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
# File 'lib/roebe/configuration/class/configuration.rb', line 102

def initialize(
    commandline_arguments = ARGV,
    run_already           = true
  )
  reset
  if run_already.to_s.include? 'dont'
    run_already = false
  end
  case run_already
  # ======================================================================= #
  # === :default
  # ======================================================================= #
  when :default
    run_already = true
  # ======================================================================= #
  # === :dont_run_yet
  # ======================================================================= #
  when :dont_run_yet,
       :do_not_run_yet
    run_already = false
  end
  # ======================================================================= #
  # The following code will handle the situation where the user gives
  # a specific directory as main path to use. The class will then
  # set that directory as the new primary directory to use, and
  # then will also load the individual .yml files at once. This is
  # done primarily for convenience-reasons.
  # ======================================================================= #
  if commandline_arguments and commandline_arguments.is_a?(Array) and
     !commandline_arguments.empty? 
    unless commandline_arguments.first.start_with?('--')
      if File.directory?(commandline_arguments.first)
        try_to_use_this_as_new_directory(commandline_arguments.first)
      end
    end
  end
  set_commandline_arguments(commandline_arguments)
  run if run_already
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(this_method, *args, &block) ⇒ Object

#

method_missing

#

Raises:

  • (ArgumentError)


651
652
653
654
655
656
657
658
659
# File 'lib/roebe/configuration/class/configuration.rb', line 651

def method_missing(
    this_method,
    *args,
    &block
  )
  string = "The method called `#{this_method}` is not defined."
  e(string)
  raise ArgumentError.new(string)
end

Class Method Details

.[](i = ARGV) ⇒ Object

#

Roebe::Configuration::Configuration[]

#


956
957
958
# File 'lib/roebe/configuration/class/configuration.rb', line 956

def self.[](i = ARGV)
  new(i)
end

Instance Method Details

#add_alias(new_alias, existing_method) ⇒ Object

#

add_alias

Use this method to add an alias.

#


341
342
343
344
345
346
347
348
349
# File 'lib/roebe/configuration/class/configuration.rb', line 341

def add_alias(
    new_alias, existing_method
  )
  new_alias       = new_alias.to_sym unless new_alias.is_a? Symbol
  existing_method = existing_method.to_sym unless existing_method.is_a? Symbol
  self.class.class_eval {
    alias_method new_alias, existing_method
  }
end

#add_this_method(this_method, optional_new_value = :derive_from_the_method_name) ⇒ Object Also known as: add, try_to_update, []=, set_configuration_value_for, set

#

add_this_method (add tag)

This is the only way how one should add new methods to the object.

It will add a getter and a setter method.

Te first argument to this method should be the key of the main Hash, e. g. :editor. The second argument is then the value that is to be assigned to this key - at the least for the reader method. Obviously for the setter you supply another value anyway, such as via “.editor = vim”. The second argument can be omitted, in which case the default, assumed value will be used, queried from the main Hash at hand.

If the first argument is something like this ‘ editor = bluefish’ then we assume that the user wants to split this based on the ‘=’ token.

#


762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
# File 'lib/roebe/configuration/class/configuration.rb', line 762

def add_this_method(
    this_method,
    optional_new_value = :derive_from_the_method_name
  )
  if this_method.is_a? String
    this_method = this_method.dup if this_method.frozen?
    this_method.strip!
  end
  if this_method.is_a?(String) and this_method.include?('=') # Also check if it has a =
    splitted = this_method.split('=').map(&:strip)
    this_method = splitted[0] # e. g. "fancy_editor".
    optional_new_value = splitted[1] # e. g. "bluefish".
  end
  this_method = this_method.to_sym if USE_ONLY_SYMBOLS_AS_KEY # We try to keep only symbols for now.
  # ======================================================================= #
  # The following case/when menu will honour two shortcuts, as String, and
  # one Symbol. The String-shortcuts are "f" meaning false, and "t",
  # meaning true.
  # ======================================================================= #
  case optional_new_value
  # ======================================================================= #
  # === :derive_from_the_method_name
  # ======================================================================= #
  when :derive_from_the_method_name
    optional_new_value = @internal_hash[:configuration_dataset][this_method.to_sym]
  # ======================================================================= #
  # === f
  # ======================================================================= #
  when 'f'
    optional_new_value = false
  # ======================================================================= #
  # === t
  # ======================================================================= #
  when 't'
    optional_new_value = true
  end
  self.class.class_eval {
    # ===================================================================== #
    # First, we will add the getter:
    # ===================================================================== #
    define_method(this_method.to_sym) {
      return obtain(this_method)
    } unless ARRAY_THESE_METHODS_SHALL_NOT_BE_OVERWRITTEN.include?(this_method.to_sym) # This check was added in December 2023.
    # ===================================================================== #
    # Next, we will add the setter, unless the last character is "?":
    # ===================================================================== #
    unless this_method.to_s.end_with?('?')
      _ = (this_method.to_s+'=').to_sym # Here we create a setter.
      define_method(_) {|new_value_to_use| # Define the setter here.
        @internal_hash[:configuration_dataset][this_method.to_sym] =
          new_value_to_use
      }
    end
  }
end

#array_methods_that_were_defined?Boolean Also known as: store_which_keys?

#

array_methods_that_were_defined?

#

Returns:

  • (Boolean)


277
278
279
# File 'lib/roebe/configuration/class/configuration.rb', line 277

def array_methods_that_were_defined? 
  @internal_hash[:array_methods_that_were_defined]
end

#be_verbose?Boolean

#

be_verbose?

#

Returns:

  • (Boolean)


739
740
741
# File 'lib/roebe/configuration/class/configuration.rb', line 739

def be_verbose?
  @internal_hash[:be_verbose]
end

#check(i) ⇒ Object

#

check

#


537
538
539
# File 'lib/roebe/configuration/class/configuration.rb', line 537

def check(i)
  return obtain(i) if has_this_key? i
end

#configuration_dataset?Boolean Also known as: data?, configuration_as_hash, configuration_dataset

#

configuration_dataset?

This query-method will return the content of the configuration dataset. Before the rewrite in May 2022 it was called @_, but that name was not a very good name.

#

Returns:

  • (Boolean)


231
232
233
# File 'lib/roebe/configuration/class/configuration.rb', line 231

def configuration_dataset?
  @internal_hash[:configuration_dataset]
end

#consider_creating_missing_yaml_filesObject

#

consider_creating_missing_yaml_files

According to our specification, if we have a key-value pair in our hash, we must also have a corresponding yaml file. In order to do this, we query all keys from @_ and then check whether that file already exists.

#


571
572
573
574
575
576
577
578
579
580
581
582
# File 'lib/roebe/configuration/class/configuration.rb', line 571

def consider_creating_missing_yaml_files
  keys?.each {|entry|
    entry = entry.to_s # Need to work with a String.
    _ = read_in_from_which_directory?+entry+'.yml' 
    unless File.exist? _ # The file does not exist, thus create it.
      if shall_we_debug?
        opn; e 'Now creating file '+sfile(_)+'.'
      end
      create_file(_) # This method is defined in this file here.
    end
  } if File.directory?(read_in_from_which_directory?)
end

#convert_global_env(i) ⇒ Object

#

convert_global_env

#


731
732
733
734
# File 'lib/roebe/configuration/class/configuration.rb', line 731

def convert_global_env(i)
  return ConvertGlobalEnv.convert(i) if Object.const_defined?(:ConvertGlobalEnv)
  return i
end

#create_directory(i) ⇒ Object

#

create_directory

#


319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
# File 'lib/roebe/configuration/class/configuration.rb', line 319

def create_directory(i)
  i = i.to_s
  if i.include?('$')
    i = convert_global_env(i)
  end
  if be_verbose?
    opn; e "Now creating the directory `#{i}`."
  end
  base_dir = File.dirname(i)+'/'
  if File.writable?(i)
    FileUtils.mkdir_p(i)
  else
    opn; e  'Can not write into `'+base_dir+'` because '
            'of insufficient permissions.'
  end
end

#create_file(i, be_verbose = be_verbose? ) ⇒ Object

#

create_file

Use this method if you wish to create a file. We tap into the toplevel functionality in ::Roebe for that behaviour.

#


703
704
705
706
707
708
709
710
# File 'lib/roebe/configuration/class/configuration.rb', line 703

def create_file(
    i,
    be_verbose = be_verbose?
  )
  if be_verbose
    opn; e "Now creating the file `#{sfile(i)}`."
  end
end

#define_these_methods(i = ) ⇒ Object

#

define_these_methods

#


904
905
906
907
908
909
910
# File 'lib/roebe/configuration/class/configuration.rb', line 904

def define_these_methods(
    i = @internal_hash[:array_methods_that_were_defined]
  )
  i.each {|this_method|
    add_this_method(this_method)
  }
end

#do_save_the_configuration(hash = configuration_dataset?, , be_verbose = false, shall_we_debug = shall_we_debug? ) ⇒ Object Also known as: save_configuration, save_config, save, do_save

#

do_save_the_configuration (save tag)

This method can be used to save the configuration. Be sure to really want to save the configuration before calling this method.

#


358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
# File 'lib/roebe/configuration/class/configuration.rb', line 358

def do_save_the_configuration(
    hash           = configuration_dataset?,
    be_verbose     = false,
    shall_we_debug = shall_we_debug?
  )
  case shall_we_debug
  # ======================================================================= #
  # === :debug
  # ======================================================================= #
  when :debug,
       :be_verbose
    shall_we_debug = true
  # ======================================================================= #
  # === :no
  # ======================================================================= #
  when :no,
       :do_not_debug
    shall_we_debug = false
  end
  case hash
  # ======================================================================= #
  # === :default
  # ======================================================================= #
  when :default
    hash = configuration_dataset?
  end
  case be_verbose
  # ======================================================================= #
  # === :be_verbose
  # ======================================================================= #
  when :be_verbose
    be_verbose = true
  end
  store_into_this_directory = store_yaml_files_into_that_directory?
  if !File.directory?(store_into_this_directory) and
     shall_we_create_missing_base_directory?
    # ===================================================================== #
    # Create the directory in this case.
    # ===================================================================== #
    create_directory(store_into_this_directory)
  end
  if File.directory? store_into_this_directory # First ensure that the base directory exis
    notify_the_user = true
    store_which_keys?.each {|this_key|
      if !this_key.is_a?(Symbol) and store_only_symbols_as_keys?
        this_key = this_key.to_sym
      end
      what = hash[this_key]
      target = "#{store_into_this_directory}#{this_key}.yml"
      if be_verbose
        e "The .yml file will be stored at: "\
          "#{target}"
      end
      if File.writable? File.dirname(target) # Only act if we can write to the hdd.
        if shall_we_debug
          opne "Now saving into `#{sfile(target)}`."
          pp what # Debug-info.
        end
        # ================================================================= #
        # Next we will use YAML.dump() and then the custom method called
        # Roebe.write_what_into(), to store the content of the .yml
        # file.
        # ================================================================= #
        Roebe.write_what_into(
          YAML.dump(what),
          target,
          permission: @internal_hash[:permission_to_use]
        )
      else
        if notify_the_user
          opne 'You do not have sufficient permission to modify this directory:'
          e "  #{store_into_this_directory}"
          notify_the_user = false # We notify the user only once, to avoid spam.
        end
      end
    }
  else
    opne 'Sorry, the directory at '+sdir(store_into_this_directory)
    opne "#{rev}does not exist."
  end
end

#ensure_that_the_proper_output_directory_existsObject

#

ensure_that_the_proper_output_directory_exists

This method will check whether the base directory exists or not.

The constant SHALL_WE_CREATE_MISSING_BASE_DIRECTORY tells us whether we will create the base directory if it is missing.

#


549
550
551
552
553
554
555
556
557
558
559
560
561
# File 'lib/roebe/configuration/class/configuration.rb', line 549

def ensure_that_the_proper_output_directory_exists
  _ = base_dir?
  if _
    _ = convert_global_env(_) if _.include?('$')
    unless File.directory? _
      opn; e 'Warning: The designated base directory at'
      opn; e _+' does not exist.'
      opn; e 'We will however create it now, as set by the'
      opn; e 'constant SHALL_WE_CREATE_MISSING_BASE_DIRECTORY.'
      create_directory(_)
    end if shall_we_create_missing_base_directory?
  end
end

#first_argument?Boolean

#

first_argument?

#

Returns:

  • (Boolean)


686
687
688
# File 'lib/roebe/configuration/class/configuration.rb', line 686

def first_argument?
  @internal_hash[:commandline_arguments].first
end

#has_method?(i) ⇒ Boolean Also known as: has?, has_entry?

#

has_method?

Use this method to find out whether the configuration-object responds to a certain method.

#

Returns:

  • (Boolean)


504
505
506
507
# File 'lib/roebe/configuration/class/configuration.rb', line 504

def has_method?(i)
  i = i.to_sym
  respond_to? i
end

#has_this_key?(i) ⇒ Boolean Also known as: has_key?, include?

#

has_this_key?

Query whether we include a key or not.

#

Returns:

  • (Boolean)


455
456
457
458
459
# File 'lib/roebe/configuration/class/configuration.rb', line 455

def has_this_key?(i)
  i = i.to_s # Default.
  i = i.to_sym if the_keys_are_symbols?
  dataset?.has_key?(i)
end

#internal_hash?Boolean Also known as: hash_internal, registered_methods?, internal?

#

internal_hash?

#

Returns:

  • (Boolean)


513
514
515
# File 'lib/roebe/configuration/class/configuration.rb', line 513

def internal_hash?
  @internal_hash
end

#internal_set_be_verboseObject Also known as: internal_be_verbose

#

internal_set_be_verbose

This awkward name has been given because we want to allow the user to still use a file called “be_verbose.yml” or a method called “set_be_verbose”.

#


220
221
222
# File 'lib/roebe/configuration/class/configuration.rb', line 220

def internal_set_be_verbose
  @internal_hash[:be_verbose] = true
end

#keys?Boolean Also known as: keys

#

keys (keys tag)

Use this method when you wish to obtain the keys from the internal dataset.

#

Returns:

  • (Boolean)


263
264
265
# File 'lib/roebe/configuration/class/configuration.rb', line 263

def keys?
  configuration_dataset?.keys.sort
end

#lets_debugObject

#

lets_debug

#


312
313
314
# File 'lib/roebe/configuration/class/configuration.rb', line 312

def lets_debug
  @internal_hash[:shall_we_debug] = true
end

#lets_not_debugObject

#

lets_not_debug

#


305
306
307
# File 'lib/roebe/configuration/class/configuration.rb', line 305

def lets_not_debug
  @internal_hash[:shall_we_debug] = false
end

#load_yaml_files_from_this_path=(i = read_from_which_directory? ) ⇒ Object Also known as: try_to_use_this_as_new_directory=, try_to_use_this_as_new_directory, load_the_default_dataset, load_the_default, start, load_yaml_files, read_in_dataset_from_existing_yaml_files, reload, load_dataset, from_this_dir=, set_load_yaml_files_from_this_path, slurp=, slurp

#

load_yaml_files_from_this_path=

This is the main “loader-method”, aka the one that loads all .yml files from a specific directory. Thus, the default work-mode for this method is to pass in a file path. This should be a String, such as:

'/home/x/programming/ruby/src/roebe/lib/roebe/shell/yaml/configuration/'
#


849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
# File 'lib/roebe/configuration/class/configuration.rb', line 849

def load_yaml_files_from_this_path=(
    i = read_from_which_directory?
  )
  debug = shall_we_debug?
  set_read_yaml_files_from_this_directory(i)
  hash = {}
  if File.directory? i
    remove_all_old_registered_methods # Start from a clean state.
    work_on_these_files = Dir[(i+'/*.yml').squeeze('/')]
    work_on_these_files.each {|this_yaml_file|
      begin
        yaml_dataset = YAML.load_file(this_yaml_file)
          name_of_the_entry = File.basename(this_yaml_file).
                            delete_suffix('.yml')
        if debug # Only feedback message if we are verbose.
          opn; e 'Reading in this entry next: `'+sfancy(name_of_the_entry)+'`'
          opn; e '(from `'+this_yaml_file+'`).'
        end
        @internal_hash[:array_methods_that_were_defined]
        name_of_the_entry = name_of_the_entry.to_sym if symbols_only_as_keys?
        hash[name_of_the_entry] = yaml_dataset
        @internal_hash[:array_methods_that_were_defined] << name_of_the_entry.to_sym
        @internal_hash[:array_methods_that_were_defined] << (name_of_the_entry.to_s+'?').to_sym # And the '?' variant as well.
      rescue Exception => error
        opn; e 'An error happened in '+sfile(THIS_FILE)+
               ' at line '+__LINE__.to_s
        opn; e 'The file where it occurred was: `'+sfile(this_yaml_file)+'`.'
        e
        pp error
        e
      end
    }
    @internal_hash[:configuration_dataset].merge!(hash)
    define_these_methods(@internal_hash[:array_methods_that_were_defined])
  else
    raise 'Must provide a directory path here. Instead given was: '+
           i+' ('+i.class.to_s+')'
  end
end

#n_methods_defined?Boolean Also known as: n_methods?

#

n_methods_defined?

This is a bit hackish, since we only count the size of the main Array at hand.

#

Returns:

  • (Boolean)


287
288
289
# File 'lib/roebe/configuration/class/configuration.rb', line 287

def n_methods_defined?
  @internal_hash[:array_methods_that_were_defined].size
end

#obtain(this_key) ⇒ Object Also known as: []

#

obtain (obtain tag)

This method can be used to run a query against the main dataset (the main Hash) of this class.

If we save the keys only as symbols (determined through the constant called USE_ONLY_SYMBOLS_AS_KEY), we need to convert the given input into proper symbol-format.

#


945
946
947
948
949
950
951
# File 'lib/roebe/configuration/class/configuration.rb', line 945

def obtain(this_key)
  if this_key.to_s.end_with?('?')
    this_key = this_key.to_s.chop
  end
  this_key = this_key.to_sym if the_keys_are_symbols?
  return configuration_dataset?[this_key]
end

#opnObject

#

opn

#


492
493
494
495
496
# File 'lib/roebe/configuration/class/configuration.rb', line 492

def opn
  if Object.const_defined?(:Opn)
    Opn.opn(namespace: NAMESPACE)
  end
end

#opnnObject

#

opnn

#


446
447
448
# File 'lib/roebe/configuration/class/configuration.rb', line 446

def opnn
  Opn.opn(namespace: NAMESPACE)
end

#read_yaml_files_from_this_directory?Boolean Also known as: read_from_which_directory?, read_in_from_which_directory?

#

read_yaml_files_from_this_directory

#

Returns:

  • (Boolean)


587
588
589
# File 'lib/roebe/configuration/class/configuration.rb', line 587

def read_yaml_files_from_this_directory?
  @internal_hash[:read_yaml_files_from_this_directory]
end

#remove_all_old_registered_methods(i = ) ⇒ Object Also known as: get_rid_of_the_registered_methods

#

remove_all_old_registered_methods

This method will remove all registered methods by default. It is a way to restore the initial clean setup of the Configuration class.

#


919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
# File 'lib/roebe/configuration/class/configuration.rb', line 919

def remove_all_old_registered_methods(
    i = @internal_hash[:array_methods_that_were_defined]
  )
  i.each {|this_method|
    this_method = this_method.to_sym
    self.class.class_eval {
      remove_method(this_method) if respond_to?(this_method)
      if respond_to?((this_method.to_s+'=').to_sym)
        remove_method(
          (this_method.to_s+'=').to_sym # And remove the setter method as well.
        )
      end
    }
  }
end

#report_the_entriesObject Also known as: report, entries

#

report_the_entries (report tag)

This method shows the entries.

#


250
251
252
253
254
# File 'lib/roebe/configuration/class/configuration.rb', line 250

def report_the_entries
  keys?.each {|entry|
    e "  - #{entry}"
  }
end

#resetObject

#

reset (reset tag)

This configuration object can not directly set too many @ivars because these could conflict with @ivars defined by the user.

For instance, if we were to set @be_verbose on this main configuration object, then this @ivar would be pre-set for that project. And we don’t always want to do that. For this reason, we use a hash instead as opposed to various different @ivars, and we call this hash @internal_hash, to reflect the fact that it has nothing to do with methods set and defined by a user.

#


155
156
157
158
159
160
161
162
163
164
165
166
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
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/roebe/configuration/class/configuration.rb', line 155

def reset
  # ======================================================================= #
  # === @internal_hash
  # ======================================================================= #
  @internal_hash = {}
  # ======================================================================= #
  # === :configuration_dataset
  #
  # The next variable keeps all configuration-specific data. This is by
  # far the most important variable of this class, so it comes first
  # after @internal_hash has been defined.
  # ======================================================================= #
  @internal_hash[:configuration_dataset] = {}
  # ======================================================================= #
  # === :read_yaml_files_from_this_directory
  # ======================================================================= #
  @internal_hash[:read_yaml_files_from_this_directory] = nil
  # ======================================================================= #
  # === :store_yaml_files_into_that_directory
  #
  # The variable :store_yaml_files_into_that_directory keeps track
  # into which directory the configuration will be saved into.
  #
  # This will be handled by the method
  # .set_store_yaml_files_into_that_directory().
  #
  # ======================================================================= #
  set_store_yaml_files_into_that_directory(:default_target) # Initialize the main directory here.
  # ======================================================================= #
  # === :array_methods_that_were_defined
  # ======================================================================= #
  @internal_hash[:array_methods_that_were_defined] = []
  # ======================================================================= #
  # === :shall_we_create_missing_base_directory
  # ======================================================================= #
  @internal_hash[:shall_we_create_missing_base_directory] = SHALL_WE_CREATE_MISSING_BASE_DIRECTORY
  # ======================================================================= #
  # === :permission_to_use
  # ======================================================================= #
  @internal_hash[:permission_to_use] = '0644' # The permission bit to use when creating a file from this class.
  # ======================================================================= #
  # === :shall_we_debug
  # ======================================================================= #
  @internal_hash[:shall_we_debug] = ::Roebe::Configuration.debug?
  # ======================================================================= #
  # === :be_verbose
  # ======================================================================= #
  @internal_hash[:be_verbose] = false
  try_to_require_the_colours_gem
end

#return_configurationObject

#

return_configuration

#


693
694
695
# File 'lib/roebe/configuration/class/configuration.rb', line 693

def return_configuration
  Hash[data?.sort_by(&:first)]
end

#return_pwdObject

#

return_pwd

#


270
271
272
# File 'lib/roebe/configuration/class/configuration.rb', line 270

def return_pwd
  "#{Dir.pwd}/".squeeze('/')
end

#runObject

#

run (run tag)

#


825
826
827
828
829
830
831
832
833
834
835
836
837
# File 'lib/roebe/configuration/class/configuration.rb', line 825

def run
  _ = first_argument?
  if _ and
     File.directory?(_) and
     @internal_hash[:read_yaml_files_from_this_directory].nil?
    # ===================================================================== #
    # This will be only run if the above variable is nil. This code was
    # added in June 2022.
    # ===================================================================== #
    set_config_dir(_)
    set_load_yaml_files_from_this_path(_)
  end
end

#set_commandline_arguments(i) ⇒ Object

#

set_commandline_arguments

#


679
680
681
# File 'lib/roebe/configuration/class/configuration.rb', line 679

def set_commandline_arguments(i)
  @internal_hash[:commandline_arguments] = [i].flatten.compact
end

#set_create_missing_base_directory_if_it_does_not_existObject

#

set_create_missing_base_directory_if_it_does_not_exist

#


241
242
243
# File 'lib/roebe/configuration/class/configuration.rb', line 241

def set_create_missing_base_directory_if_it_does_not_exist
  @internal_hash[:shall_we_create_missing_base_directory] = true
end

#set_read_yaml_files_from_this_directory(i) ⇒ Object Also known as: read_yaml_files_from_this_directory=, read_in_from_this_dir=, read_from_this_directory=

#

set_read_yaml_files_from_this_directory

#


522
523
524
525
526
527
528
529
530
# File 'lib/roebe/configuration/class/configuration.rb', line 522

def set_read_yaml_files_from_this_directory(i)
  if i
    if i.include?('$')
      i = convert_global_env(i) # Assume global env.
    end
    @internal_hash[:read_yaml_files_from_this_directory] = i
  end
  return i
end

#set_store_yaml_files_into_that_directory(i = :default_target) ⇒ Object Also known as: store_yaml_files_into_that_directory=, set_store_into_this_directory, store_into_this_directory=, store_into_that_dir=, set_base_directory, set_base_dir, base_directory, base_dir=, config_dir=, set_directory, load, set_config_dir, set_configuration_directory

#

set_store_yaml_files_into_that_directory

This is the setter-method to assign to the variable @internal_hash.

Some of the aliases are a bit questionable, so they are not guaranteed to be retained in the future. The name .store_into_this_directory= is more likely to be retained, though, so consider using that method name instead.

Usage examples:

configuration.store_into_this_directory = ''
configuration.base_dir = ''
#


609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
# File 'lib/roebe/configuration/class/configuration.rb', line 609

def set_store_yaml_files_into_that_directory(
    i = :default_target
  )
  case i
  # ======================================================================= #
  # === :do_not_use_a_base_directory
  # ======================================================================= #
  when :do_not_use_a_base_directory
    i = nil
  # ======================================================================= #
  # === :default_target
  # ======================================================================= #
  when :default_target
    i = '/tmp/configuration/'
  end
  if i
    i = i.to_s unless i.is_a?(String) # We want Strings past this point.
    if i.include?('$')
      i = convert_global_env(i) # Assume global env.
    end
    i = i.dup if i.frozen?
    i << '/' unless i.end_with?('/') # Must be a directory, so it must have a trailing /.
    i.strip!
  end
  @internal_hash[:store_yaml_files_into_that_directory] = i
end

#sfile(i) ⇒ Object

#

sfile

#


715
716
717
# File 'lib/roebe/configuration/class/configuration.rb', line 715

def sfile(i)
  ::Colours.sfile(i)
end

#shall_we_create_missing_base_directory?Boolean

#

shall_we_create_missing_base_directory?

#

Returns:

  • (Boolean)


209
210
211
# File 'lib/roebe/configuration/class/configuration.rb', line 209

def shall_we_create_missing_base_directory?
  @internal_hash[:shall_we_create_missing_base_directory]
end

#shall_we_debug?Boolean Also known as: shall_we_debug

#

shall_we_debug?

This should only be used internally, as it may otherwise conflict with a method defined in a .yml file.

#

Returns:

  • (Boolean)


297
298
299
# File 'lib/roebe/configuration/class/configuration.rb', line 297

def shall_we_debug?
  @internal_hash[:shall_we_debug]
end

#show_configurationObject Also known as: show_config

#

show_configuration

Use this method to show the configuration settings.

#


475
476
477
478
479
480
481
482
483
484
485
486
487
# File 'lib/roebe/configuration/class/configuration.rb', line 475

def show_configuration
  if base_dir?
    opn; e 'The configuration of this class, taken from'
    opn; e 'the base directory at'
    e
    e "  #{base_dir?}"
    e
    opn; e 'is as follows:'
    e
    pp return_configuration # data?
    e
  end
end

#the_keys_are_symbols?Boolean Also known as: symbols_only_as_keys?, store_only_symbols_as_keys?

#

the_keys_are_symbols?

#

Returns:

  • (Boolean)


465
466
467
# File 'lib/roebe/configuration/class/configuration.rb', line 465

def the_keys_are_symbols?
  USE_ONLY_SYMBOLS_AS_KEY
end

#try_to_require_the_colours_gemObject

#

try_to_require_the_colours_gem

#


722
723
724
725
726
# File 'lib/roebe/configuration/class/configuration.rb', line 722

def try_to_require_the_colours_gem
  begin
    require 'colours'
  rescue LoadError; end
end