therubymug-hitch 0.0.3 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  Hitch allows developers to be properly credited when Pair Programming and using Git.
8
8
 
9
- == FEATURES/PROBLEMS:
9
+ == FEATURES:
10
10
 
11
11
  * Persists pair(s) between different terminal instances.
12
12
  * Creates a unique email address for the pair. (e.g. dev+leshill+therubymug@hashrocket.com) This provides the ability to create a Gravatar for the pair.
@@ -14,13 +14,17 @@ Hitch allows developers to be properly credited when Pair Programming and using
14
14
  == SYNOPSIS:
15
15
 
16
16
  - First, create your hitchrc by running:
17
- - hitchrc
18
- - To pair with leshill:
19
- - hitch leshill
20
- - To see a list of available pairs:
21
- - hitch -i
22
- - To clear pair info:
23
- - unhitch
17
+ - hitch -m
18
+ - For therubymug and leshill to pair in the current project:
19
+ - hitch leshill therubymug
20
+ - or globally:
21
+ - hitch -g leshill therubymug
22
+ - To clear pair info (for the local project):
23
+ - hitch -u
24
+ - To clear pair info in the global file:
25
+ - hitch -u -g
26
+ - For a complete list of features:
27
+ - hitch -h
24
28
  - Creating a Gravatar for your pair:
25
29
  - Once I've hitched with my pair. (e.g. hitch leshill) I have now created a unique email: dev+leshill+therubymug@hashrocket.com
26
30
  - Then, I go to gravatar.com. Add an image to that particular email address and I'm done.
@@ -35,8 +39,9 @@ Hitch allows developers to be properly credited when Pair Programming and using
35
39
 
36
40
  == ACKNOWLEDGEMENTS:
37
41
 
38
- * Les Hill - Refactoring.
39
- * Tim Pope - Original idea.
42
+ * Les Hill
43
+ * Tim Pope
44
+ * Bodaniel Jeanes
40
45
 
41
46
  == LICENSE:
42
47
 
data/Rakefile CHANGED
@@ -25,6 +25,7 @@ PROJ.url = 'http://github.com/therubymug/hitch'
25
25
  PROJ.version = Hitch::VERSION
26
26
  PROJ.rubyforge.name = 'hitch'
27
27
  PROJ.dependencies = ['highline']
28
+ PROJ.readme_file = 'README.rdoc'
28
29
 
29
30
  PROJ.spec.opts << '--color'
30
31
 
data/bin/hitch CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require 'rubygems'
3
4
  require File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib hitch]))
4
5
  include Hitch
5
6
 
data/bin/hitchrc CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require 'rubygems'
3
4
  require File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib hitch]))
4
5
  include Hitch
5
6
 
6
- create_hitchrc
7
+ manage_hitchrc
data/bin/unhitch CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require 'rubygems'
3
4
  require File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib hitch]))
4
5
  include Hitch
5
6
 
@@ -0,0 +1,67 @@
1
+ require 'optparse'
2
+ require 'optparse/time'
3
+ require 'ostruct'
4
+
5
+ module Hitch
6
+
7
+ class Options
8
+
9
+ def self.parse(args)
10
+ options = OpenStruct.new
11
+ options.action = "hitch"
12
+
13
+ opts = OptionParser.new do |opts|
14
+ opts.banner = "Usage: hitch [options] first_pair_username second_pair_username"
15
+ opts.separator ""
16
+ opts.separator "Hitch defaults to the current project's .git/config"
17
+ opts.separator ""
18
+ opts.separator "General options:"
19
+
20
+ opts.on("-g", "--global", "Modifies your global ~/.gitconfig") do
21
+ options.current_gitconfig = File.expand_path("~/.gitconfig")
22
+ end
23
+
24
+ opts.on("-m", "--manage-hitchrc", "Creates or manages your personal information into ~/.hitchrc") do
25
+ if options.action.empty? || options.action == "hitch"
26
+ options.action = "manage_hitchrc"
27
+ else
28
+ abort "You can only perform one action at a time. hitch -h for more info."
29
+ end
30
+ end
31
+
32
+ opts.on("-u", "--unhitch", "Clear pair information") do
33
+ if options.action.empty? || options.action == "hitch"
34
+ options.action = "unhitch"
35
+ else
36
+ abort "You can only perform one action at a time. hitch -h for more info."
37
+ end
38
+ end
39
+
40
+ opts.separator ""
41
+ opts.separator "Common options:"
42
+
43
+ opts.on_tail("-h", "--help", "Show this message") do
44
+ puts opts
45
+ exit
46
+ end
47
+
48
+ opts.on_tail("-v", "--version", "Show version") do
49
+ abort "hitch v#{Hitch.version}"
50
+ end
51
+ end
52
+
53
+ opts.parse!(args)
54
+
55
+ if options.current_gitconfig.nil?
56
+ options.current_gitconfig = File.expand_path(File.join(Dir.pwd, ".git", "config"))
57
+ end
58
+
59
+ unless File.exists?(options.current_gitconfig)
60
+ abort "Config File: #{options.current_gitconfig} does not exist. hitch -h for more info."
61
+ end
62
+
63
+ options
64
+ end
65
+
66
+ end
67
+ end
data/lib/hitch.rb CHANGED
@@ -1,8 +1,10 @@
1
1
  require 'highline'
2
+ require File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib hitch options]))
2
3
 
3
4
  module Hitch
5
+
4
6
  # :stopdoc:
5
- VERSION = '0.0.3'
7
+ VERSION = '0.5.0'
6
8
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
7
9
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
8
10
  # :startdoc:
@@ -45,7 +47,7 @@ module Hitch
45
47
  HighLine.track_eof = false
46
48
 
47
49
  def write_hitchrc
48
- personal_info['pairing_with'] = pairing_with
50
+ personal_info['current_pair'] = current_pair
49
51
  File.open(hitchrc, File::CREAT|File::TRUNC|File::RDWR, 0644) do |out|
50
52
  YAML.dump(personal_info, out)
51
53
  end
@@ -85,17 +87,9 @@ module Hitch
85
87
  @ui ||= HighLine.new
86
88
  end
87
89
 
88
- def valid_hitchrc?(hitchrc)
89
- return false if hitchrc.empty?
90
- return false if hitchrc['my_name'].empty?
91
- return false if hitchrc['my_github'].empty?
92
- return false if hitchrc['group_email'].empty?
93
- return true
94
- end
95
-
96
90
  def write_gitconfig
97
91
  clean_gitconfig
98
- File.open(File.join(ENV['HOME'], ".gitconfig"), "a+") do |f|
92
+ File.open(hitch_options.current_gitconfig, "a+") do |f|
99
93
  f.puts "# start - lines added by hitch #"
100
94
  f.puts "[user]"
101
95
  f.puts "\tname = '#{hitch_name}'"
@@ -105,13 +99,13 @@ module Hitch
105
99
  end
106
100
 
107
101
  def add_pair(git_name)
108
- pairing_with << git_name
109
- pairing_with.sort!
110
- pairing_with.uniq!
102
+ current_pair << git_name
103
+ current_pair.sort!
104
+ current_pair.uniq!
111
105
  end
112
106
 
113
- def pairing_with
114
- @pairing_with ||= (personal_info['pairing_with'] or [])
107
+ def current_pair
108
+ @current_pair ||= (personal_info['current_pair'] or [])
115
109
  end
116
110
 
117
111
  def hitch_name
@@ -123,8 +117,7 @@ module Hitch
123
117
  end
124
118
 
125
119
  def my_pairs_and_i
126
- and_i = pairing_with.map {|github| [github, pairs[github]]}
127
- and_i << [personal_info['my_github'], personal_info['my_name']]
120
+ and_i = current_pair.map {|github| [github, pairs[github]]}
128
121
  and_i.sort_by {|github, name| github }
129
122
  end
130
123
 
@@ -136,8 +129,9 @@ module Hitch
136
129
  personal_info['group_email'].split('@').last
137
130
  end
138
131
 
139
- def clean_gitconfig
140
- config_file = File.expand_path("~/.gitconfig")
132
+ def clean_gitconfig(opts={:print => false})
133
+ config_file = hitch_options.current_gitconfig
134
+ ui.say " Clearing hitch info in: #{config_file}" if opts[:print]
141
135
  body = File.read(config_file)
142
136
  body.gsub!(/# start - lines added by hitch #\n.*?\n# end - lines added by hitch #\n/m, '')
143
137
  File.open(config_file + ".tmp", 'w') {|f| f.write(body)}
@@ -156,14 +150,14 @@ module Hitch
156
150
  if personal_info
157
151
  clear_pair_info
158
152
  write_hitchrc
159
- clean_gitconfig
153
+ clean_gitconfig(:print => true)
160
154
  print_current_status
161
155
  end
162
156
  end
163
157
 
164
158
  def print_current_status
165
159
  if pairing?
166
- ui.say " Currently pairing with #{pairing_with.join(' ')}."
160
+ ui.say " Currently pairing with #{current_pair.join(' ')}."
167
161
  else
168
162
  ui.say " Currently coding solo."
169
163
  end
@@ -173,24 +167,14 @@ module Hitch
173
167
  ui.say "hitch v#{Hitch.version}"
174
168
  end
175
169
 
176
- def print_help
177
- print_version
178
- ui.say ""
179
- ui.say "Usage:"
180
- ui.say "\thitch <github_username>"
181
- ui.say "\thitch -i to see all available pairs"
182
- ui.say "\tunhitch to clear"
183
- ui.say "\thitchrc to create ~/.hitchrc"
184
- ui.say ""
185
- end
186
-
187
170
  def clear_pair_info
188
- personal_info['pairing_with'] = []
171
+ personal_info['current_pair'] = []
189
172
  end
190
173
 
191
174
  def pairing?
192
175
  return false if personal_info.empty?
193
- return false if personal_info['pairing_with'].nil? || personal_info['pairing_with'].length.zero?
176
+ return false if personal_info['current_pair'].nil? || personal_info['current_pair'].length.zero?
177
+ return false if personal_info['current_pair'].length < 2
194
178
  true
195
179
  end
196
180
 
@@ -198,75 +182,52 @@ module Hitch
198
182
  pairs.any? {|github, name| github == pair}
199
183
  end
200
184
 
201
- def interactive
202
- key = pair_name = ""
203
- ui.choose do |menu|
204
- menu.prompt = "Who is your pair?"
205
- pairs.sort_by {|github, name| github }.each do |github, name|
206
- menu_label = github == personal_info['my_github'] ? "#{github}: #{personal_info['my_name']} (Pick yourself to code solo)" : "#{github}: #{name}"
207
- menu.choice(menu_label) do
208
- clear_pair_info
209
- unless github == personal_info['my_github']
210
- add_pair(github)
211
- end
212
- end
213
- end
214
- end
215
- write_hitchrc
216
- prep_gitconfig
185
+ def hitch_options
186
+ @hitch_options ||= Options.parse(ARGV)
217
187
  end
218
188
 
219
189
  def hitch
220
- opts = ARGV
221
- case opts
222
- when ["-i"]
223
- interactive
224
- when ["-h"]
225
- print_help
226
- when ["-v"]
227
- print_version
228
- else
229
- if opts.any?
190
+ case hitch_options.action
191
+ when "manage_hitchrc"
192
+ manage_hitchrc
193
+ when "unhitch"
194
+ unhitch
195
+ when "hitch"
196
+ if ARGV.any? && ARGV.size >= 2
197
+ potential_pairs = ARGV
230
198
  save_pairs = false
231
199
  clear_pair_info
232
200
 
233
- opts.each do |opt|
234
- unless existing_pair?(opt)
235
- ui.say("I don't know who #{opt} is.")
236
- if ui.agree("Do you want to add #{opt} to ~/.hitch_pairs? ", true)
237
- pairs[opt] = ui.ask("What is #{opt}'s full name?") do |q|
238
- q.validate = /\A[(\w+)\s?]+\Z/
201
+ potential_pairs.each do |pair|
202
+ unless existing_pair?(pair)
203
+ ui.say("I don't know who #{pair} is.")
204
+ if ui.agree("Do you want to add #{pair} to ~/.hitch_pairs? ", true)
205
+ pairs[pair] = ui.ask("What is #{pair}'s full name?") do |q|
206
+ q.validate = /\A[(\w|.,)+\s?]+\Z/
239
207
  end
240
- add_pair(opt)
208
+ add_pair(pair)
241
209
  save_pairs ||= true
242
210
  else
243
- ui.say("Ignoring #{opt}.")
211
+ ui.say("Ignoring #{pair}.")
244
212
  end
245
213
  else
246
- add_pair(opt)
214
+ add_pair(pair)
247
215
  end
248
216
  end
249
217
  write_hitchrc
250
218
  write_hitch_pairs if save_pairs
251
219
  prep_gitconfig
220
+ else
221
+ ui.say " Silly Rabbit! A pair is comprised of two." unless ARGV.size.zero?
252
222
  end
253
-
254
223
  print_current_status
255
224
  end
256
225
  end
257
226
 
258
- def create_hitchrc
227
+ def manage_hitchrc
259
228
  begin
260
229
  unless File.exists?(hitchrc) and !ui.agree("Do you want to overwrite your #{ENV['HOME']}/.hitchrc file?", true)
261
- ui.say("We need to setup your #{ENV['HOME']}/.hitchrc file")
262
- personal_info['my_name'] = ui.ask("What is your full name?") do |q|
263
- q.validate = /\A([\w\.\(\)]+\s?)+\z/
264
- end
265
-
266
- personal_info['my_github'] = ui.ask("What is your github username?") do |q|
267
- q.case = :down
268
- q.validate = /\A[a-z0-9\-]+\z/
269
- end
230
+ ui.say("Let's setup your #{ENV['HOME']}/.hitchrc file")
270
231
 
271
232
  personal_info['group_email'] = ui.ask("What is the group email? e.g. dev@hashrocket.com will become dev+therubymug+leshill@hashrocket.com") do |q|
272
233
  q.case = :down
@@ -284,5 +245,3 @@ module Hitch
284
245
  end # module Hitch
285
246
 
286
247
  Hitch.require_all_libs_relative_to(__FILE__)
287
-
288
- # EOF
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: therubymug-hitch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rogelio Samour
@@ -40,8 +40,10 @@ files:
40
40
  - bin/hitchrc
41
41
  - bin/unhitch
42
42
  - lib/hitch.rb
43
+ - lib/hitch/options.rb
43
44
  has_rdoc: false
44
45
  homepage: http://github.com/therubymug/hitch
46
+ licenses:
45
47
  post_install_message:
46
48
  rdoc_options: []
47
49
 
@@ -62,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
62
64
  requirements: []
63
65
 
64
66
  rubyforge_project:
65
- rubygems_version: 1.2.0
67
+ rubygems_version: 1.3.5
66
68
  signing_key:
67
69
  specification_version: 2
68
70
  summary: Hitch allows developers to be properly credited when Pair Programming and using Git.