Class: Git::Delta::Runner
- Inherits:
-
Object
- Object
- Git::Delta::Runner
- Defined in:
- lib/git-delta/run.rb
Instance Method Summary collapse
- #exclude ⇒ Object
- #parse_arg(argv) ⇒ Object
- #rails ⇒ Object
- #run(argv = ARGV) ⇒ Object
- #total_lines(paths, extensions) ⇒ Object
Instance Method Details
#exclude ⇒ Object
27 28 29 |
# File 'lib/git-delta/run.rb', line 27 def exclude @excl ||= (File.read('./.ignore_commits') rescue File.read('tmp/.ignore_commits') rescue '') end |
#parse_arg(argv) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/git-delta/run.rb', line 15 def parse_arg(argv) @verbose ||= ARGV.delete('-v') split = Hash.new{|h, k| h['path']}.merge!('.' => [], '-' => [], 'path' => []) if ARGV.delete('-new') # beurk split['-'] << 'origin/master.. ' end argv.each{|a| split[a[0]] << a} split.values_at('path', '.', '-') end |
#rails ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/git-delta/run.rb', line 31 def rails app = %w[app lib] categs = { js: [app, %w[js coffee]], ruby: [app, %w[rb]], erb: [app, %w[erb haml hbs]], app: [app, %w[erb haml rb js coffee hbs]], test: [%w[test spec], %w[rb]], } pmd = categs.map do |kind, args| Git::Delta::Reporter.new(*args).filter_out(exclude).plus_minus_delta end kinds = categs.keys # pmd << pmd.transpose.map{|s| s.inject(:+)} # kinds << 'total' categs.zip(pmd) do |(kind, (paths, extensions)), (p, m, d)| tot = total_lines(paths, extensions) puts "%10s: %4d %5d = %5d (%2.2f%% of %d)" % [kind, p, m, d, 100.0 * d / tot, tot] end end |
#run(argv = ARGV) ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/git-delta/run.rb', line 4 def run(argv = ARGV) case ARGV.first when '-rails' rails when '-h', '--help' puts "This is just a quick script, check the readme or the source code" else Git::Delta::Reporter.new(*parse_arg(argv)).filter_out(exclude).report(@verbose) end end |
#total_lines(paths, extensions) ⇒ Object
55 56 57 58 59 |
# File 'lib/git-delta/run.rb', line 55 def total_lines(paths, extensions) paths.product(extensions).map do |path, ext| `find #{path} -name '*.#{ext}' -print0 | xargs -0 wc -l | tail -1`.to_i end.inject(:+) end |