class Cookbooks::CreateGlobalYamlDatabase

Constants

NAMESPACE
#

NAMESPACE

#
STORE_HERE
#

STORE_HERE

#

Public Class Methods

new( run_already = true ) click to toggle source
#

initialize

#
# File lib/cookbooks/utility_scripts/create_global_yaml_database.rb, line 35
def initialize(
    run_already = true
  )
  reset
  run if run_already
end
store_where?() click to toggle source
#

::store_where?

#
# File lib/cookbooks/utility_scripts/create_global_yaml_database.rb, line 66
def self.store_where?
  STORE_HERE
end

Public Instance Methods

encoding?() click to toggle source
#

encoding?

#
# File lib/cookbooks/utility_scripts/create_global_yaml_database.rb, line 52
def encoding?
  USE_THIS_ENCODING
end
iterate_over_every_program() click to toggle source
#

#iterate_over_every_program

#
# File lib/cookbooks/utility_scripts/create_global_yaml_database.rb, line 93
def iterate_over_every_program
  @all_programs.each_with_index {|program, index|
    dataset = Cookbooks::Cookbook.new(program) { :bypass_menu }
    dataset = dataset.dataset?
    hash = {}
    program = program.encode(encoding?)
    hash[program] = dataset
    _ = {}
    dataset.each_pair {|key, value|
      if key
        key = key.encode(encoding?)
        begin
          value = value.encode(encoding?) if value.is_a? String
        rescue Encoding::InvalidByteSequenceError
          opnn; e swarn('Error for '+simp(value))
          exit
        end
        _[key] = value
      end
    }
    dataset = _
    opnn; e "Now working on the program #{simp(program)}."
    @dataset.merge!(hash)
  }
end
obtain_all_programs() click to toggle source
#

#obtain_all_programs

#
# File lib/cookbooks/utility_scripts/create_global_yaml_database.rb, line 86
def obtain_all_programs
  @all_programs = Cookbooks.available_programs
end
opnn() click to toggle source
#

opnn

#
Calls superclass method Cookbooks::Base#opnn
# File lib/cookbooks/utility_scripts/create_global_yaml_database.rb, line 59
def opnn
  super(NAMESPACE)
end
reset() click to toggle source
#

reset

#
# File lib/cookbooks/utility_scripts/create_global_yaml_database.rb, line 45
def reset
  @dataset = Hash.new # This is the main hash.
end
run() click to toggle source
#

run

#
# File lib/cookbooks/utility_scripts/create_global_yaml_database.rb, line 122
def run
  obtain_all_programs
  iterate_over_every_program
  store_into_yaml_file
end
store_into_yaml_file() click to toggle source
#

#store_into_yaml_file

#
# File lib/cookbooks/utility_scripts/create_global_yaml_database.rb, line 73
def store_into_yaml_file
  into = STORE_HERE
  opnn; e "Now storing into `#{sfile(into)}`."
  if File.exist? into
    File.delete(into) # Always get rid of the old yaml file first.
  end
  what = YAML.dump(@dataset)
  save_what_into(what, into)
end