Skip to content

Commit

Permalink
Expire pair information in N hours
Browse files Browse the repository at this point in the history
Closes #7
  • Loading branch information
therubymug committed Sep 5, 2011
1 parent 7b6cbb3 commit 7882c13
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 37 deletions.
10 changes: 9 additions & 1 deletion bin/hitch
@@ -1,6 +1,7 @@
#!/usr/bin/env ruby

require File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib hitch]))
require File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib hitch version]))

args = ARGV
options = []
Expand All @@ -11,6 +12,9 @@ opts = OptionParser.new do |opts|
opts.on("-s", "--setup", "Print out shell goodies") do
options = [:setup]
end
opts.on("-e N", "--expire N", Integer, "Expire pair information in N hours.") do |n|
options = [:expire, n]
end
opts.on("-u", "--unhitch", "Clear pair information") do
options = [:unhitch]
end
Expand All @@ -21,11 +25,15 @@ opts = OptionParser.new do |opts|
exit
end
opts.on_tail("-v", "--version", "Show version") do
abort "hitch v#{Hitch.version}"
abort "hitch v#{Hitch::VERSION}"
end
end

if args.any?
opts.parse!(args)
if options.delete(:expire)
system(Hitch.expire_command(options.pop))
end
options = [:export, args] if options.empty?
else
options = [:print_info]
Expand Down
50 changes: 20 additions & 30 deletions hitch.gemspec
@@ -1,46 +1,36 @@
require File.expand_path("../lib/hitch/version", __FILE__)

Gem::Specification.new do |s|
s.name = %q{hitch}
s.version = "0.6.1"
s.version = Hitch::VERSION
s.platform = Gem::Platform::RUBY

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Rogelio J. Samour"]
s.date = %q{2010-10-10}
s.default_executable = %q{hitch}
s.required_rubygems_version = ">= 1.3.6"
s.authors = [%q{Rogelio J. Samour}]
s.date = Time.now.strftime('%F')
s.email = %q{rogelio@therubymug.com}
s.executables = ["hitch"]
s.files = [
"Rakefile",
"bin/hitch",
"lib/hitch.rb",
"lib/hitch/author.rb",
"lib/hitch/ui.rb"
]
s.executables = [%q{hitch}]
s.files = Dir["{lib}/**/*.rb", "bin/*", "Rakefile", "MIT_LICENSE", "*.md"]
s.homepage = %q{http://github.com/therubymug/hitch}
s.rdoc_options = ["--charset=UTF-8"]
s.require_paths = ["lib"]
s.rubygems_version = %q{1.3.7}
s.rdoc_options = [%q{--charset=UTF-8}]
s.require_paths = [%q{lib}]
s.rubygems_version = %q{1.8.6}
s.description = %q{Git author attribution helper for pair programmers.}
s.summary = %q{Hitch allows developers to be properly credited when Pair Programming and using Git.}
s.test_files = [
"spec/helper.rb",
"spec/hitch/author_spec.rb",
"spec/hitch/ui_spec.rb",
"spec/hitch_spec.rb"
]
s.test_files = Dir["{spec}/**/*.rb"]

if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 3

if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_development_dependency(%q<rspec>, [">= 1.3.0"])
s.add_runtime_dependency(%q<highline>, [">= 1.5.0"])
s.add_development_dependency(%q<rspec>, [">= 2.6.0"])
s.add_runtime_dependency(%q<highline>, [">= 1.6.2"])
else
s.add_dependency(%q<rspec>, [">= 1.3.0"])
s.add_dependency(%q<highline>, [">= 1.5.0"])
s.add_dependency(%q<rspec>, [">= 2.6.0"])
s.add_dependency(%q<highline>, [">= 1.6.2"])
end
else
s.add_dependency(%q<rspec>, [">= 1.3.0"])
s.add_dependency(%q<highline>, [">= 1.5.0"])
s.add_dependency(%q<rspec>, [">= 2.6.0"])
s.add_dependency(%q<highline>, [">= 1.6.2"])
end
end

23 changes: 17 additions & 6 deletions lib/hitch.rb
Expand Up @@ -6,12 +6,6 @@

module Hitch

VERSION = '0.6.1'

def self.version
VERSION
end

def self.print_info
if Hitch.pairing? && STDOUT.tty?
Hitch::UI.highline.say("#{Hitch.git_author_name} <#{Hitch.git_author_email}>")
Expand All @@ -24,6 +18,10 @@ def self.export(pairs)
print_info
end

def self.expire_command(time)
%Q(sleep #{to_seconds(time)} && #{Hitch.bin_path} --unhitch&)
end

def self.unhitch
Hitch.current_pair = []
write_export_file
Expand Down Expand Up @@ -123,10 +121,23 @@ def self.hitch_export_authors
File.expand_path('~/.hitch_export_authors')
end

def self.bin_path
%x[which hitch].chomp
end

def self.pairing?
current_pair.any?
end

def self.to_seconds(value)
value = value.to_s.gsub(/[^\d]/, '').to_i
unless value.zero?
value * 60 * 60
else
raise StandardError
end
end

def self.write_export_file
File.open(hitch_export_authors, 'w'){|f| f.write(author_command) }
end
Expand Down
3 changes: 3 additions & 0 deletions lib/hitch/version.rb
@@ -0,0 +1,3 @@
module Hitch
VERSION = "0.7.0"
end
28 changes: 28 additions & 0 deletions spec/hitch_spec.rb
Expand Up @@ -14,6 +14,34 @@
Hitch::Author.stub(:available_pairs).and_return(hitch_pairs)
end

describe '.expire_command' do
before do
Hitch.stub(:bin_path).and_return('/usr/local/bin/hitch')
end

context 'with a valid string' do
let(:time_string) { '8' }
it 'returns the system command to call' do
Hitch.expire_command(time_string).should == 'sleep 28800 && /usr/local/bin/hitch --unhitch&'
end
end

context 'with a valid integer' do
let(:time_string) { 8 }
it 'returns the system command to call' do
Hitch.expire_command(time_string).should == 'sleep 28800 && /usr/local/bin/hitch --unhitch&'
end
end

context 'with an invalid string' do
let(:time_string) { 'BAR' }
it 'raises an error' do
expect {Hitch.expire_command(time_string)}.to raise_error(StandardError)
end
end

end

describe '.author_command' do

context 'when pairing' do
Expand Down

0 comments on commit 7882c13

Please sign in to comment.