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
- .quiet(&_block) ⇒ Object
- .which(name) ⇒ Object
- .with_path(path, &_block) ⇒ Object
Class Method Details
.command(name) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/githooks/system_utils.rb', line 47 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
57 58 59 |
# File 'lib/githooks/system_utils.rb', line 57 def commands(*names) names.each { |name| command(name) } end |
.find_bin(name) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/githooks/system_utils.rb', line 15 def find_bin(name) # rubocop:disable MultilineBlockChain, Blocks ENV['PATH'].split(/:/).collect { |path| Pathname.new(path) + name.to_s }.select { |path| path.exist? && path.executable? }.collect(&:to_s) # rubocop:enable MultilineBlockChain, Blocks end |
.quiet(&_block) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/githooks/system_utils.rb', line 38 def quiet(&_block) od, ov = GitHooks.debug, GitHooks.verbose GitHooks.debug, GitHooks.verbose = false, false yield ensure GitHooks.debug, GitHooks.verbose = od, ov 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
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/githooks/system_utils.rb', line 26 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 |