Module: Shellter::ClassMethods
- Included in:
- Shellter
- Defined in:
- lib/shellter/class_methods.rb
Instance Method Summary collapse
- #run(command, *arguments) ⇒ Object
- #run!(command, *arguments) ⇒ Object
- #which(command, paths = nil) ⇒ Object
Instance Method Details
#run(command, *arguments) ⇒ Object
3 4 5 6 7 8 |
# File 'lib/shellter/class_methods.rb', line 3 def run(command, *arguments) Command.new(command, *arguments).tap do |command| = arguments. command.run() end end |
#run!(command, *arguments) ⇒ Object
10 11 12 13 14 |
# File 'lib/shellter/class_methods.rb', line 10 def run!(command, *arguments) run(command, *arguments).tap do |result| raise "Execution failed, with exit code #{result.exit_code}" unless result.success? end end |
#which(command, paths = nil) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/shellter/class_methods.rb', line 16 def which(command, paths = nil) paths ||= ENV["PATH"].split(File::PATH_SEPARATOR) extensions = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] paths.each do |path| extensions.each do |extension| path_with_extension(path, command, extension).tap do |path_to_command| if File.exists?(path_to_command) && File.executable?(path_to_command) return path_to_command end end end end nil end |