Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Expire pair information in N hours

Closes #7
  • Loading branch information...
commit 7882c132b9532879515477366687312634ddf2e6 1 parent 7b6cbb3
@therubymug authored
View
10 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 = []
@@ -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
@@ -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]
View
50 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
-
View
23 lib/hitch.rb
@@ -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}>")
@@ -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
@@ -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
View
3  lib/hitch/version.rb
@@ -0,0 +1,3 @@
+module Hitch
+ VERSION = "0.7.0"
+end
View
28 spec/hitch_spec.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.