module Kernel
Kernel
module additions
These methods, all of which are prefixed with “nucleon_” are available in any class or module within the Nucleon
framework or derivatives.
We also define a generic debug dump method that is available in any Nucleon
derived class or module.
Public Instance Methods
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
# File lib/nucleon_base.rb 402 def dbg(data, label = '', override_enabled = false) 403 # Invocations of this function should NOT be committed to the project 404 if Nucleon.dump_enabled || override_enabled 405 require 'pp' 406 puts '>>----------------------' 407 unless ! label || label.empty? 408 puts label 409 puts '---' 410 end 411 pp data 412 puts '<<' 413 end 414 end
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
# File lib/nucleon_base.rb 34 def nucleon_locate(command) 35 command = command.to_s 36 exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] 37 ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| 38 exts.each do |ext| 39 exe = File.join(path, "#{command}#{ext}") 40 return exe if File.executable?(exe) 41 end 42 end 43 return nil 44 end
Require resource files into Nucleon
execution flow.
This method auto-requires resources in the following order:
-
*{name}.rb*
-
*{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
# File lib/nucleon_base.rb 66 def nucleon_require(base_dir, name) 67 base_dir = base_dir.to_s 68 name = name.to_s 69 top_level_file = File.join(base_dir, "#{name}.rb") 70 71 require top_level_file if File.exists?(top_level_file) 72 73 directory = File.join(base_dir, name) 74 75 if File.directory?(directory) 76 Dir.glob(File.join(directory, '**', '*.rb')).each do |sub_file| 77 require sub_file 78 end 79 end 80 end