Module: CommandKit::Env::Path
- Includes:
- CommandKit::Env
- Included in:
- OpenApp, PackageManager, Pager
- Defined in:
- lib/command_kit/env/path.rb
Overview
Provides access to the PATH
environment variable.
Environment Variables
PATH
- The list of directories to search for commands within.
Instance Attribute Summary collapse
-
#path_dirs ⇒ Array<String>
readonly
The home directory.
Attributes included from CommandKit::Env
Instance Method Summary collapse
-
#command_installed?(name) ⇒ Boolean
Determines if the command is present on the system.
-
#find_command(name) ⇒ String?
Searches for the command in #path_dirs.
-
#initialize(**kwargs) ⇒ Object
Initializes #path_dirs using
env['PATH']
.
Instance Attribute Details
#path_dirs ⇒ Array<String> (readonly)
The home directory.
22 23 24 |
# File 'lib/command_kit/env/path.rb', line 22 def path_dirs @path_dirs end |
Instance Method Details
#command_installed?(name) ⇒ Boolean
Determines if the command is present on the system.
81 82 83 |
# File 'lib/command_kit/env/path.rb', line 81 def command_installed?(name) !find_command(name).nil? end |
#find_command(name) ⇒ String?
Searches for the command in #path_dirs.
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/command_kit/env/path.rb', line 50 def find_command(name) name = name.to_s @path_dirs.each do |dir| file = File.join(dir,name) return file if File.file?(file) && File.executable?(file) end return nil end |
#initialize(**kwargs) ⇒ Object
Initializes #path_dirs using env['PATH']
.
32 33 34 35 36 |
# File 'lib/command_kit/env/path.rb', line 32 def initialize(**kwargs) super(**kwargs) @path_dirs = env.fetch('PATH','').split(File::PATH_SEPARATOR) end |