kata 1.3.2 → 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,11 +1,13 @@
1
1
  ## Kata
2
2
 
3
3
  A kata is defined as an exercise in programming which helps hone your skills through practice and
4
- repetition. Authoring katas is done in blogs but you can't really test yourself. This gem provides a
5
- DSL to author the kata and administer it as a test providing feedback for evaluation. It also
6
- provides basic github repo setup so that you can chart solution progress over time.
7
-
8
- The inspiration for this gem came from my friend [Nick Hengeveld](https://github.com/nickh)
4
+ repetition. Authoring katas is done in blogs but you can't really test yourself.
5
+ [coderdojo](http://www.coderdojo.com) is a fine website and provides a great way to get involved
6
+ with katas. The purpose of this gem is to provide a work environment based way of interacting.
7
+ It provides several facilities for authoring and taking katas that allow you to work in your own
8
+ environment. The inspiration for this gem came from my friend [Nick
9
+ Hengeveld](https://github.com/nickh) who first introduced me to the concept of a kata several years
10
+ ago.
9
11
 
10
12
  ### Installation
11
13
 
@@ -27,7 +29,7 @@ or do it the old fashioned way and install the gem manually:
27
29
 
28
30
  DESCRIPTION
29
31
  The kata gem allows one to manage their personal development in the
30
- practice of writing code through repitition.
32
+ practice of writing code through repetition.
31
33
 
32
34
  PRIMARY COMMANDS
33
35
  kata setup [--no-repo] [--language=option] file
@@ -64,7 +66,7 @@ The [Wiki](https://github.com/wbailey/kata/wiki) has all of the documentation ne
64
66
 
65
67
  ### License
66
68
 
67
- Copyright (c) 2011-2013 Wes Bailey
69
+ Copyright (c) 2011-2014 Wes Bailey
68
70
 
69
71
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
70
72
  associated documentation files (the "Software"), to deal in the Software without restriction,
data/bin/kata CHANGED
@@ -13,7 +13,7 @@ SYNOPSIS
13
13
 
14
14
  DESCRIPTION
15
15
  The kata gem allows one to manage their personal development in the
16
- practice of writing code through repitition.
16
+ practice of writing code through repetition.
17
17
 
18
18
  PRIMARY COMMANDS
19
19
  kata setup [--no-repo] [--language=option] file
@@ -68,7 +68,7 @@ case options.action
68
68
  name = nil
69
69
 
70
70
  File.open(options.file).each do |line|
71
- if line.match /^kata *\"([^\"]*)\" *do$/
71
+ if line.match(/^kata *\"([^\"]*)\" *do$/)
72
72
  name = $1
73
73
  break
74
74
  end
data/lib/kata/base.rb CHANGED
@@ -53,38 +53,34 @@ module Kata
53
53
  end
54
54
 
55
55
  def complete(status = true)
56
- if @@times.size > 0
57
- title = status ? 'Congratulations!' : 'You completed the following:'
56
+ return if @@times.size == 0
58
57
 
59
- formatter = lambda do |sec|
60
- use = sec.round
61
- [use/3600, use/60 % 60, use % 60].map {|v| v.to_s.rjust(2,'0')}.join(':')
62
- end
58
+ formatter = lambda do |sec|
59
+ use = sec.round
60
+ [use/3600, use/60 % 60, use % 60].map {|v| v.to_s.rjust(2,'0')}.join(':')
61
+ end
63
62
 
64
- suppress_output
63
+ suppress_output
65
64
 
66
- table :border => true do
67
- row :header => true do
68
- column 'Requirement', :color => 'red', :width => 80
69
- column 'Time', :color => 'red', :width => 8
70
- end
65
+ table :border => true do
66
+ row :header => true do
67
+ column 'Requirement', :color => 'red', :width => 80
68
+ column 'Time', :color => 'red', :width => 8
69
+ end
71
70
 
72
- @@times.each do |t|
73
- row do
74
- column t[:title]
75
- column formatter.call(t[:time])
76
- end
71
+ @@times.each do |t|
72
+ row do
73
+ column t[:title]
74
+ column formatter.call(t[:time])
77
75
  end
78
76
  end
77
+ end
79
78
 
80
- report = capture_output
81
-
82
- File.open('report.txt', 'w').write( report )
79
+ report = capture_output
83
80
 
84
- puts report
85
- end
81
+ File.open('report.txt', 'w').write( report )
86
82
 
87
- exit 1 unless status
83
+ puts report
88
84
  end
89
85
 
90
86
  def ancestry
@@ -1,5 +1,7 @@
1
1
  require 'fileutils'
2
2
  require 'ostruct'
3
+ require 'octokit'
4
+ require 'io/console'
3
5
 
4
6
  module Kata
5
7
  module Setup
@@ -13,64 +15,92 @@ module Kata
13
15
  end
14
16
 
15
17
  def create_repo options
18
+ create_remote_repo if options.repo
19
+
20
+ push_local_repo(options.repo)
21
+ end
22
+
23
+ def repo_name=(kata_name)
24
+ @repo_name = "#{kata_name.gsub(/( |-)\1?/, '_')}-#{Time.now.strftime('%Y-%m-%d-%H%M%S')}".downcase
25
+ end
26
+
27
+ def build_tree(type = 'ruby')
28
+ case type
29
+ when 'ruby'
30
+ Kata::Setup::Ruby.new(kata_name).build_tree
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def github
16
37
  # Setup from github configuration
17
- raise Exception, 'Git not installed' unless system 'which git > /dev/null'
38
+ raise Exception, 'Git not installed? Could not find git using which' unless system('which git > /dev/null')
18
39
 
19
- github = OpenStruct.new :url => 'http://github.com/api/v2/json/'
40
+ @github ||=
41
+ begin
42
+ tmp = OpenStruct.new
20
43
 
21
- github_user, shell_user = %x{git config --get github.user}.chomp, ENV['USER']
44
+ github_user = %x{git config --get github.user}.chomp
45
+ shell_user = ENV['USER']
22
46
 
23
- github.user = github_user.empty? ? shell_user : github_user
47
+ tmp.user = github_user.empty? ? shell_user : github_user
24
48
 
25
- raise Exception, 'Unable to determine github user' if github.user.empty?
49
+ raise Exception, 'Unable to determine github user' if tmp.user.empty?
26
50
 
27
- github.token = %x{git config --get github.token}.chomp
51
+ print 'Github account password: '
52
+ tmp.password = STDIN.noecho(&:gets).chomp
28
53
 
29
- raise Exception, 'Unable to determine github api token' if github.token.empty?
54
+ tmp
55
+ end
56
+ end
30
57
 
31
- user_string = "-u '#{github.user}/token:#{github.token}'"
32
- repo_params = "-d 'name=#{repo_name}' -d 'description=code+kata+repo'"
58
+ def client
59
+ @client ||= Octokit::Client.new(:login => github.user, :password => github.password)
60
+ end
33
61
 
34
- # Create the repo on github
35
- if options.repo
36
- print 'Creating github repo...'
37
- raise SystemCallError, 'unable to use curl to create repo on github' unless system <<-EOF
38
- curl -s #{user_string} #{repo_params} #{github.url}repos/create 2>&1 > /dev/null;
39
- EOF
40
- puts 'complete'
41
- end
62
+ def create_session_token
63
+ authorization = client.create_authorization({:scopes => ['public_repo'], :note => 'Ruby Kata'})
42
64
 
43
- # publish to github
65
+ github.token = authorization.token
66
+
67
+ cmd = "git config --add github.token #{github.token}"
68
+ raise SystemCallError, 'Unable to cache github api token' unless system(cmd)
69
+ end
44
70
 
45
- print 'creating files for repo and initializing...'
71
+ def create_remote_repo
72
+ create_session_token
46
73
 
47
- cmd = "cd #{repo_name};"
48
- if options.repo
49
- cmd << "git init 2>&1 > /dev/null;"
50
- cmd << "git add README .rspec lib/ spec/ 2>&1 > /dev/null;"
74
+ puts "Creating remote repo..."
75
+ client.create_repo "#{repo_name}"
76
+ puts "end"
77
+ end
78
+
79
+ def push_local_repo(new_repo)
80
+ print "creating files for repo and initializing..."
81
+
82
+ cmd = "cd #{repo_name} &&"
83
+
84
+ if new_repo
85
+ cmd << "git init >/dev/null 2>&1 &&"
86
+ cmd << "git add README .rspec lib/ spec/ >/dev/null 2>&1 &&"
51
87
  else
52
- cmd << "git add #{ENV['PWD']}/#{repo_name};"
88
+ cmd << "git add #{ENV['PWD']}/#{repo_name} >/dev/null 2>&1;"
89
+ end
90
+
91
+ cmd << "git commit -m 'starting kata' > /dev/null 2>&1;"
92
+
93
+ if new_repo
94
+ cmd << "git remote add origin git@github.com:#{github.user}/#{repo_name}.git >/dev/null 2>&1 &&"
53
95
  end
54
- cmd << "git commit -m 'starting kata' 2>&1 > /dev/null;"
55
- cmd << "git remote add origin git@github.com:#{github.user}/#{repo_name}.git 2>&1 > /dev/null;" if options.repo
56
- cmd << 'git push origin master 2> /dev/null'
96
+
97
+ cmd << 'git push origin master'
57
98
 
58
99
  raise SystemCallError, 'unable to add files to github repo' unless system(cmd)
59
100
 
60
101
  puts 'done'
61
102
  puts "You can now change directories to #{repo_name} and take your kata"
62
103
  end
63
-
64
- def repo_name=(kata_name)
65
- @repo_name = "#{kata_name.gsub(/( |-)\1?/, '_')}-#{Time.now.strftime('%Y-%m-%d-%H%M%S')}".downcase
66
- end
67
-
68
- def build_tree(type = 'ruby')
69
- case type
70
- when 'ruby'
71
- Kata::Setup::Ruby.new(kata_name).build_tree
72
- end
73
- end
74
104
  end
75
105
  end
76
106
  end
data/lib/kata/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Kata
2
- VERSION = '1.3.2'
2
+ VERSION = '1.3.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kata
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2
4
+ version: 1.3.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-03-09 00:00:00.000000000 Z
13
+ date: 2014-02-05 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
17
- requirement: &2156425380 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,15 @@ dependencies:
22
22
  version: 1.0.0
23
23
  type: :development
24
24
  prerelease: false
25
- version_requirements: *2156425380
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: 1.0.0
26
31
  - !ruby/object:Gem::Dependency
27
32
  name: command_line_reporter
28
- requirement: &2156424600 !ruby/object:Gem::Requirement
33
+ requirement: !ruby/object:Gem::Requirement
29
34
  none: false
30
35
  requirements:
31
36
  - - ! '>='
@@ -33,7 +38,12 @@ dependencies:
33
38
  version: 3.2.1
34
39
  type: :runtime
35
40
  prerelease: false
36
- version_requirements: *2156424600
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: 3.2.1
37
47
  description: This DSL provides an easy way for you to write a code kata for pairing
38
48
  exercises or individual testing
39
49
  email: baywes@gmail.com
@@ -54,8 +64,7 @@ files:
54
64
  - spec/spec_helper.rb
55
65
  - spec/support/helpers/stdout_helper.rb
56
66
  - spec/support/matchers/kata.rb
57
- - !binary |-
58
- YmluL2thdGE=
67
+ - bin/kata
59
68
  homepage: http://github.com/wbailey/kata
60
69
  licenses: []
61
70
  post_install_message:
@@ -68,6 +77,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
68
77
  - - ! '>='
69
78
  - !ruby/object:Gem::Version
70
79
  version: '0'
80
+ segments:
81
+ - 0
82
+ hash: -2352903460502696782
71
83
  required_rubygems_version: !ruby/object:Gem::Requirement
72
84
  none: false
73
85
  requirements:
@@ -76,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
88
  version: '0'
77
89
  requirements: []
78
90
  rubyforge_project:
79
- rubygems_version: 1.8.15
91
+ rubygems_version: 1.8.25
80
92
  signing_key:
81
93
  specification_version: 3
82
94
  summary: A code kata DSL