Module: GitHooks::SystemUtils
- Included in:
- Repository
- Defined in:
- lib/githooks/system_utils.rb
Defined Under Namespace
Classes: Command
Class Method Summary collapse
- .command(name) ⇒ Object
- .commands(*names) ⇒ Object
- .find_bin(name) ⇒ Object
- .which(name) ⇒ Object
- .with_path(path, &_block) ⇒ Object
Class Method Details
.command(name) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/githooks/system_utils.rb', line 36 def command(name) (@commands ||= {})[name] ||= begin Command.new(name).tap { |cmd| define_method("command_#{cmd.name}") { |*args| cmd.execute(*args) } alias_method cmd.method, "command_#{cmd.name}" } end end |
.commands(*names) ⇒ Object
46 47 48 |
# File 'lib/githooks/system_utils.rb', line 46 def commands(*names) names.each { |name| command(name) } end |
.find_bin(name) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/githooks/system_utils.rb', line 15 def find_bin(name) ENV['PATH'].split(/:/).collect { |path| Pathname.new(path) + name.to_s }.select { |path| path.exist? && path.executable? }.collect(&:to_s) end |
.which(name) ⇒ Object
10 11 12 |
# File 'lib/githooks/system_utils.rb', line 10 def which(name) find_bin(name).first end |
.with_path(path, &_block) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/githooks/system_utils.rb', line 24 def with_path(path, &_block) fail ArgumentError, 'Missing required block' unless block_given? begin cwd = Dir.getwd Dir.chdir path yield path ensure Dir.chdir cwd end end |