Module: Overcommit::Utils
- Defined in:
- lib/overcommit/utils.rb
Constant Summary collapse
- @@hooks =
[]
Class Method Summary collapse
- .absolute_path(path) ⇒ Object
- .hook_name ⇒ Object
- .load_hooks ⇒ Object
-
.modified_files ⇒ Object
Get a list of staged Added, Copied, or Modified files (ignore renames and deletions, since there should be nothing to check).
- .register_hook(hook) ⇒ Object
-
.repo_path(path) ⇒ Object
File.expand_path takes one more ‘..’ than you’re used to…
- .run_hooks(*args) ⇒ Object
- .script_path(script) ⇒ Object
-
.underscorize(str) ⇒ Object
Shamelessly stolen from: stackoverflow.com/questions/1509915/converting-camel-case-to-underscore-case-in-ruby.
Class Method Details
.absolute_path(path) ⇒ Object
29 30 31 |
# File 'lib/overcommit/utils.rb', line 29 def absolute_path(path) File.join(File.('../../..', __FILE__), path) end |
.hook_name ⇒ Object
14 15 16 |
# File 'lib/overcommit/utils.rb', line 14 def hook_name File.basename($0).tr('-', '_') end |
.load_hooks ⇒ Object
18 19 20 21 22 23 |
# File 'lib/overcommit/utils.rb', line 18 def load_hooks require File.("../hooks/#{hook_name}", __FILE__) rescue LoadError log.error "No hook definition found for #{hook_name}" exit 1 end |
.modified_files ⇒ Object
Get a list of staged Added, Copied, or Modified files (ignore renames and deletions, since there should be nothing to check).
52 53 54 |
# File 'lib/overcommit/utils.rb', line 52 def modified_files `git diff --cached --name-only --diff-filter=ACM --ignore-submodules=all`.split "\n" end |
.register_hook(hook) ⇒ Object
6 7 8 |
# File 'lib/overcommit/utils.rb', line 6 def register_hook(hook) @@hooks << hook end |
.repo_path(path) ⇒ Object
File.expand_path takes one more ‘..’ than you’re used to… we want to go two directories up from the caller (which will be .git/hooks/something) to the root of the git repo.
36 37 38 |
# File 'lib/overcommit/utils.rb', line 36 def repo_path(path) File.join(File.('../../..', $0), path) end |
.run_hooks(*args) ⇒ Object
10 11 12 |
# File 'lib/overcommit/utils.rb', line 10 def run_hooks(*args) @@hooks.each { |hook| hook.new.run(*args) } end |
.script_path(script) ⇒ Object
25 26 27 |
# File 'lib/overcommit/utils.rb', line 25 def script_path(script) File.join(File.('../../hooks/scripts', $0), script) end |
.underscorize(str) ⇒ Object
Shamelessly stolen from: stackoverflow.com/questions/1509915/converting-camel-case-to-underscore-case-in-ruby
42 43 44 45 46 47 48 |
# File 'lib/overcommit/utils.rb', line 42 def underscorize(str) str.gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2'). gsub(/([a-z\d])([A-Z])/, '\1_\2'). tr('-', '_'). downcase end |