Module: Kernel

Defined in:
lib/nucleon_base.rb,
lib/nucleon_base.rb

Overview

We also define a generic debug dump method that is available in any Nucleon derived class or module.

Instance Method Summary collapse

Instance Method Details

#dbg(data, label = '', override_enabled = false) ⇒ Object

Dump data to the console with optional label.

This must be defined under the definition of Nucleon::dump_enabled

  • Parameters

    • ANY

      data Data to dump to the console

    • String

      label Label to render above data dump

    • Boolean

      override_enabled Whether or not to override override Nucleon::dump_enabled

  • Returns

    • Void

      This method does not have a return value

  • Errors



402
403
404
405
406
407
408
409
410
411
412
413
414
# File 'lib/nucleon_base.rb', line 402

def dbg(data, label = '', override_enabled = false)
  # Invocations of this function should NOT be committed to the project
  if Nucleon.dump_enabled || override_enabled
    require 'pp'
    puts '>>----------------------'
    unless ! label || label.empty?
      puts label
      puts '---'
    end
    pp data
    puts '<<'
  end
end

#nucleon_locate(command) ⇒ Object

Locate an application command or return nil otherwise.

This is used to check for applications, such as Git, so that we may conditionally install packages based upon applications installed.

  • Parameters

    • String, Symbol

      command Command name to locale on system

  • Returns

    • nil, String

      File path to executable or nil if not found

  • Errors



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/nucleon_base.rb', line 34

def nucleon_locate(command)
  command = command.to_s
  exts    = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
  ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
    exts.each do |ext|
      exe = File.join(path, "#{command}#{ext}")
      return exe if File.executable?(exe)
    end
  end
  return nil
end

#nucleon_require(base_dir, name) ⇒ Object

Require resource files into Nucleon execution flow.

This method auto-requires resources in the following order:

  1. *name.rb*

  2. *base_dir/name/*/.rb

If resources within the directory depend on each other those requires should be present in the resource files doing the requiring so we don’t get load order conflicts.

  • Parameters

    • String, Symbol

      base_dir Command name to locale on system

    • String, Symbol

      name Command name to locale on system

  • Returns

    • Void

      This method does not have a return value

  • Errors



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/nucleon_base.rb', line 66

def nucleon_require(base_dir, name)
  base_dir       = base_dir.to_s
  name           = name.to_s
  top_level_file = File.join(base_dir, "#{name}.rb")

  require top_level_file if File.exists?(top_level_file)

  directory = File.join(base_dir, name)

  if File.directory?(directory)
    Dir.glob(File.join(directory, '**', '*.rb')).each do |sub_file|
      require sub_file
    end
  end
end