Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

First pass at code

  • Loading branch information...
commit 11f3f26ec507508a9e6e70aeee1c288191e31cdd 1 parent 38ea4e5
@bkayser authored
Showing with 79 additions and 20 deletions.
  1. +1 −0  Gemfile
  2. +1 −1  LICENSE.txt
  3. +1 −19 Rakefile
  4. +23 −0 bin/netloc
  5. +53 −0 lib/netloc.rb
View
1  Gemfile
@@ -6,6 +6,7 @@ source "http://rubygems.org"
# Add dependencies to develop your gem here.
# Include everything needed to run rake, tests, features, etc.
group :development do
+ gem "rake", ">= 0.9.2"
gem "shoulda", ">= 0"
gem "bundler", "~> 1.0.0"
gem "jeweler", "~> 1.6.4"
View
2  LICENSE.txt
@@ -1,4 +1,4 @@
-Copyright (c) 2011 Bill Kayser
+Copyright (c) 2011 Bill Kayser, New Relic, Inc.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
View
20 Rakefile
@@ -21,9 +21,8 @@ Jeweler::Tasks.new do |gem|
gem.description = %Q{TODO: longer description of your gem}
gem.email = "bkayser@newrelic.com"
gem.authors = ["Bill Kayser"]
- # dependencies defined in Gemfile
+ gem.executables = %W(netloc)
end
-Jeweler::RubygemsDotOrgTasks.new
require 'rake/testtask'
Rake::TestTask.new(:test) do |test|
@@ -32,22 +31,5 @@ Rake::TestTask.new(:test) do |test|
test.verbose = true
end
-require 'rcov/rcovtask'
-Rcov::RcovTask.new do |test|
- test.libs << 'test'
- test.pattern = 'test/**/test_*.rb'
- test.verbose = true
- test.rcov_opts << '--exclude "gems/*"'
-end
-
task :default => :test
-require 'rake/rdoctask'
-Rake::RDocTask.new do |rdoc|
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
-
- rdoc.rdoc_dir = 'rdoc'
- rdoc.title = "netloc #{version}"
- rdoc.rdoc_files.include('README*')
- rdoc.rdoc_files.include('lib/**/*.rb')
-end
View
23 bin/netloc
@@ -0,0 +1,23 @@
+#!/usr/bin/env ruby
+
+require 'optparse'
+begin
+ require 'netloc'
+rescue LoadError
+ require File.expand_path '../../lib/netloc.rb', __FILE__
+end
+
+OptionParser.new do |opts|
+ opts.banner = "Usage: netloc [<since>..<until>]"
+
+ opts.on('-h', '--help',
+ "Show the help version of this gem") do
+ puts opts; exit
+ end
+
+end.parse!
+
+Netloc.new.run
+
+
+
View
53 lib/netloc.rb
@@ -0,0 +1,53 @@
+require 'set'
+
+class Netloc
+
+ def initialize(*range)
+ @to = 'HEAD'
+ if range.empty?
+ @from = 'HEAD~2'
+ elsif range.size == 1
+ @from = range[0]
+ else
+ @from, @to = *range
+ end
+ end
+
+ def run
+ @output = %X[git log #{@from}..#{@to} --numstat --oneline].split("\n").map(&:chomp)
+ parse
+ report
+ end
+
+ def parse
+ @netapp = 0
+ @nettest = 0
+ @netother = 0
+ @files = Set.new
+ @output.each do | line |
+ if line =~ /^(\d+)\s+(\d+)\s+(.*)$/
+ process_line $1, $2, $3
+ end
+ end
+ end
+
+ def report
+ puts "App: #{'%7i' % @netapp}"
+ puts "Test: #{'%7i' % @netapp}"
+ puts "Other: #{'%7i' % @netapp}"
+ end
+
+ def process_line added, removed, file
+ puts "processing #{file}..."
+ @files << file
+ case file
+ when %r{^test/}
+ @nettest += added.to_i - removed.to_i
+ when %r{(^app/)|(\.rb$)}
+ @netapp += added.to_i - removed.to_i
+ else
+ @netother += added.to_i - removed.to_i
+ end
+ end
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.