codersdojo 1.2.08 → 1.2.09

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.
@@ -1,42 +1,41 @@
1
1
  require 'session_id_generator'
2
2
  require 'runner'
3
3
  require 'shell_argument_exception'
4
+ require 'shell_wrapper'
5
+ require 'console_view'
6
+ require 'help_command'
7
+ require 'generate_command'
8
+ require 'upload_command'
9
+ require 'upload_no_open_command'
10
+ require 'start_command'
4
11
 
5
12
  class ArgumentParser
6
13
 
7
- def initialize controller
8
- @controller = controller
14
+ def initialize shell, view, scaffolder, hostname
15
+ @help_command = HelpCommand.new view
16
+ @upload_command = UploadCommand.new shell, view, hostname
17
+ @upload_no_open_command = UploadNoOpenCommand.new @upload_command
18
+ @generate_command = GenerateCommand.new shell, view, scaffolder
19
+ @start_command = StartCommand.new shell, view, @upload_command
20
+ @commands = [@help_command, @generate_command, @start_command, @upload_command, @upload_no_open_command]
9
21
  end
10
22
 
11
- def parse params
12
- command = params[0] ? params[0].downcase : ""
13
- if command == "help" then
14
- @controller.help params[1]
15
- elsif command == "setup" then
16
- @controller.generate params[1], params[2]
17
- elsif command == "upload" then
18
- @controller.upload params[1]
19
- elsif command == "upload-no-open" then
20
- @controller.upload params[1], false
21
- elsif command == "upload-with-framework" then
22
- @controller.upload_with_framework params[1], params[2]
23
- elsif command == "start" then
24
- run_command = expand_run_command params[1]
25
- @controller.start run_command, params[2]
26
- elsif command == "spec" then
23
+ def parse params
24
+ params[0] = params[0] ? params[0].downcase : 'help'
25
+ command_name = params[0]
26
+ command_executed = false
27
+ @commands.each do |command|
28
+ if command.accepts_shell_command?(command_name)
29
+ command.execute_from_shell params
30
+ command_executed = true
31
+ end
32
+ end
33
+ if not command_executed and command_name == "spec"
27
34
  # 'spec" is for testing purpose only: do nothing special
28
- else
29
- raise ShellArgumentException.new command
35
+ elsif not command_executed
36
+ raise ShellArgumentException.new command_name
30
37
  end
31
38
  end
32
39
 
33
- def expand_run_command command
34
- if command.end_with?(".sh") then
35
- "bash #{command}"
36
- else
37
- command
38
- end
39
- end
40
-
41
40
  end
42
41
 
data/app/codersdojo.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'console_view'
4
- require 'controller'
5
4
  require 'argument_parser'
6
5
  require 'scaffolder'
7
6
 
@@ -17,10 +16,9 @@ class CodersDojo
17
16
  shell = ShellWrapper.new
18
17
  scaffolder = Scaffolder.new shell
19
18
  view = ConsoleView.new scaffolder
20
- controller = Controller.new shell, view, scaffolder, @hostname
21
19
 
22
20
  begin
23
- arg_parser = ArgumentParser.new controller
21
+ arg_parser = ArgumentParser.new shell, view, scaffolder, @hostname
24
22
  command = arg_parser.parse @params
25
23
  rescue ShellArgumentException => e
26
24
  view.show_unknwon_command_message e.command
data/app/console_view.rb CHANGED
@@ -3,6 +3,8 @@ require 'text_template_machine'
3
3
  require 'property_file_missing_exception'
4
4
 
5
5
  class ConsoleView
6
+
7
+ FRAMEWORK_LIST_INDENTATION = 6
6
8
 
7
9
  def initialize scaffolder
8
10
  @scaffolder = scaffolder
@@ -27,12 +29,6 @@ Commands:
27
29
  setup <framework> <kata_file> Setup the environment for running the kata.
28
30
  upload [<session_dir>] Upload the kata to http://www.codersdojo.org and open the kata in a browser.
29
31
  upload-no-open [<session_dir>] Upload the kata to http://www.codersdojo.org
30
- upload-with-framework <framework> [<session_dir>]
31
- Upload the kata to http://www.codersdojo.org
32
- !!! This command exists for compatibility reasons only.
33
- !!! It will be removed in the near future.
34
- !!! Please run 'setup' again to generate the .meta file
35
- !!! and use 'upload' without the 'framework' parameter.
36
32
 
37
33
  Report bugs to <codersdojo@it-agile.de>
38
34
  helptext
@@ -47,45 +43,51 @@ helptext
47
43
  show_help_upload
48
44
  elsif command == 'upload-no-open' then
49
45
  show_help_upload_no_open
50
- elsif command == 'upload-with-framework' then
51
- show_help_upload_with_framework
52
46
  else
53
47
  show_help_unknown command
54
48
  end
55
49
  end
56
50
 
57
51
  def show_help_setup
58
- templates = @scaffolder.list_templates
52
+ templates = @scaffolder.list_templates_as_dotted_list FRAMEWORK_LIST_INDENTATION
59
53
  show <<-helptext
60
54
 
61
- setup <framework> <kata_file> Setup the environment for the kata for the given framework and kata file.
62
- By now <framework> is one of #{templates}.
63
- Use ??? as framework if your framework isn't in the list.
55
+ setup <framework> <kata_file>
56
+ Setup the environment for the kata for the given framework and kata file.
57
+ The <kata_file> is the one file that will contain the source code of the code kata.
58
+ If <kata_file> does not have an extension it will be added automatically
59
+ - except if <framework> is ??? (see below).
60
+ By now <framework> is one of these:
61
+ #{templates}.
62
+ Use ??? as framework if your framework isn't in the list.
64
63
 
65
64
  Example:
66
65
  :%/%dojo%/%my_kata$ #{current_command_path} setup ruby.test-unit prime
67
- Show the instructions how to setup the environment for kata execution with Ruby and test/unit.
66
+ Setup the the environment for executing a code kata in kata file 'prime' with Ruby and test/unit.
68
67
  helptext
69
68
  end
70
69
 
71
70
  def show_help_start
72
71
  show <<-helptext
73
72
 
74
- start <shell_command> <kata_file> Start the continuous test runner, that runs <shell-command> whenever <kata_file>
75
- changes. The <kata_file> has to include the whole source code of the kata.
76
- Whenever the test runner is started, it creates a new session directory in the
77
- directory .codersdojo where it logs the steps of the kata.
73
+ start <shell_command> <kata_file>
74
+ Start the continuous test runner, that runs <shell-command> whenever <kata_file>
75
+ changes. The <kata_file> has to include the whole source code of the kata.
76
+ Whenever the test runner is started, it creates a new session directory in the
77
+ directory .codersdojo where it logs the steps of the kata.
78
78
  helptext
79
79
  end
80
80
 
81
81
  def show_help_upload
82
82
  show <<-helptext
83
83
 
84
- upload Upload the newest kata session in .codersdojo to codersdojo.com.
85
- After the kata is uploaded the browser is started with the URL of the uploaded kata.
84
+ upload
85
+ Upload the newest kata session in .codersdojo to codersdojo.com.
86
+ After the kata is uploaded the browser is started with the URL of the uploaded kata.
86
87
 
87
- upload <session_directory> Upload the kata <session_directory> to codersdojo.com.
88
- <session_directory> is relative to the working directory.
88
+ upload <session_directory>
89
+ Upload the kata <session_directory> to codersdojo.com.
90
+ <session_directory> is relative to the working directory.
89
91
 
90
92
  Examples:
91
93
  :%/%dojo%/%my_kata$ #{current_command_path} upload
@@ -98,10 +100,12 @@ helptext
98
100
  def show_help_upload_no_open
99
101
  show <<-helptext
100
102
 
101
- upload-no-open Upload the newest kata session in .codersdojo to codersdojo.com.
103
+ upload-no-open
104
+ Upload the newest kata session in .codersdojo to codersdojo.com.
102
105
 
103
- upload-no-opem <session_directory> Upload the kata <session_directory> to codersdojo.com.
104
- <session_directory> is relative to the working directory.
106
+ upload-no-opem <session_directory>
107
+ Upload the kata <session_directory> to codersdojo.com.
108
+ <session_directory> is relative to the working directory.
105
109
 
106
110
  Examples:
107
111
  :%/%dojo%/%my_kata$ #{current_command_path} upload-no-open
@@ -111,24 +115,6 @@ Examples:
111
115
  helptext
112
116
  end
113
117
 
114
- def show_help_upload_with_framework
115
- templates = @scaffolder.list_templates
116
- show <<-helptext
117
-
118
- upload-with-framework <framework> [<session_directory>]
119
- Upload the kata written with <framework> in <session_directory> to codersdojo.com.
120
- <session_directory> is relative to the working directory.
121
- If you don't specify a <session_directory> the newest session in .codersdojo is uploaded.
122
- By now <framework> is one of #{templates}.
123
- If you used another framework, use ??? and send an email to codersdojo@it-agile.de
124
- After the kata is uploaded the browser is started with the URL of the uploaded kata.
125
-
126
- Example:
127
- :%/%dojo%/%my_kata$ #{current_command_path} upload-with-framework ruby.test-unit .codersdojo%/%2010-11-02_16-21-53
128
- Upload the kata (written in Ruby with the test/unit framework) located in directory ".codersdojo%/%2010-11-02_16-21-53" to codersdojo.com.
129
- helptext
130
- end
131
-
132
118
  def show_help_unknown command
133
119
  show <<-helptext
134
120
  Command #{command} not known. Try '#{current_command_path} help' to list the supported commands.
@@ -0,0 +1,30 @@
1
+ class GenerateCommand
2
+
3
+ def initialize shell, view, scaffolder
4
+ @shell = shell
5
+ @view = view
6
+ @scaffolder = scaffolder
7
+ end
8
+
9
+ def execute_from_shell params
10
+ generate params[1], params[2]
11
+ end
12
+
13
+ def generate framework, kata_file
14
+ if not kata_file then
15
+ @view.show_missing_command_argument_error "setup", "kata_file"
16
+ return
17
+ end
18
+ begin
19
+ @scaffolder.scaffold framework, kata_file
20
+ @view.show "\n" + @shell.read_file("README")
21
+ rescue
22
+ @view.show_unknown_framework_error framework, @scaffolder.list_templates
23
+ end
24
+ end
25
+
26
+ def accepts_shell_command? command
27
+ command == 'setup'
28
+ end
29
+
30
+ end
@@ -0,0 +1,23 @@
1
+ class HelpCommand
2
+
3
+ def initialize view
4
+ @view = view
5
+ end
6
+
7
+ def execute_from_shell params
8
+ help params[1]
9
+ end
10
+
11
+ def help command=nil
12
+ if command then
13
+ @view.show_detailed_help command.downcase
14
+ else
15
+ @view.show_help
16
+ end
17
+ end
18
+
19
+ def accepts_shell_command? command
20
+ ['help', '-h', '--help'].member? command
21
+ end
22
+
23
+ end
data/app/scaffolder.rb CHANGED
@@ -16,6 +16,13 @@ class Scaffolder
16
16
  templates.join(', ')
17
17
  end
18
18
 
19
+ def list_templates_as_dotted_list indentation
20
+ templates = @shell.real_dir_entries template_path
21
+ templates.delete ANY_TEMPLATE
22
+ indent_string = ' '*indentation
23
+ "#{indent_string}* " + templates.join("\n#{indent_string}* ")
24
+ end
25
+
19
26
  def scaffold template, kata_file
20
27
  @template_machine.placeholder_values['kata_file.ext'] = kata_file
21
28
  @template_machine.placeholder_values['kata_file'] = @filename_formatter.without_extension kata_file
data/app/scheduler.rb CHANGED
@@ -1,9 +1,10 @@
1
1
  class Scheduler
2
2
 
3
- def initialize runner, view
3
+ def initialize runner, view, commands
4
4
  @runner = runner
5
5
  @view = view
6
6
  @last_action = ""
7
+ @commands = commands
7
8
  end
8
9
 
9
10
  def start
@@ -25,6 +26,11 @@ class Scheduler
25
26
  def interrupt_kata
26
27
  @view.show_kata_exit_message
27
28
  @last_action = @view.read_user_input.downcase
29
+ @commands.each do |command|
30
+ if @last_action == command.command_key
31
+ command.execute
32
+ end
33
+ end
28
34
  if last_action_was_exit? then
29
35
  @view.show_kata_upload_hint
30
36
  end
@@ -42,8 +48,4 @@ class Scheduler
42
48
  @last_action.start_with? 'e'
43
49
  end
44
50
 
45
- def last_action_was_upload?
46
- @last_action.start_with? 'u'
47
- end
48
-
49
51
  end
data/app/shell_wrapper.rb CHANGED
@@ -73,7 +73,7 @@ class ShellWrapper
73
73
  end
74
74
 
75
75
  def newest_dir_entry dir
76
- Dir.new(dir).sort_by do |entry|
76
+ real_dir_entries(dir).sort_by do |entry|
77
77
  complete_path = File.join dir, entry
78
78
  File.mtime(complete_path)
79
79
  end.last
@@ -0,0 +1,37 @@
1
+ class StartCommand
2
+
3
+ def initialize shell, view, upload_command
4
+ @shell = shell
5
+ @view = view
6
+ @upload_command = upload_command
7
+ end
8
+
9
+ def execute_from_shell params
10
+ start params[1], params[2]
11
+ end
12
+
13
+ def start command, file
14
+ unless command then @view.show_missing_command_argument_error "start", "shell_command"; return end
15
+ unless file then @view.show_missing_command_argument_error "start", "kata_file"; return end
16
+ command = expand_run_command command
17
+ @view.show_start_kata command, file, framework_property
18
+ dojo = Runner.new @shell, SessionIdGenerator.new
19
+ dojo.file = file
20
+ dojo.run_command = command
21
+ scheduler = Scheduler.new dojo, @view, [@upload_command]
22
+ scheduler.start
23
+ end
24
+
25
+ def accepts_shell_command? command
26
+ command == 'start'
27
+ end
28
+
29
+ def expand_run_command command
30
+ if command.end_with?(".sh") then
31
+ "bash #{command}"
32
+ else
33
+ command
34
+ end
35
+ end
36
+
37
+ end
data/app/state_reader.rb CHANGED
@@ -22,8 +22,7 @@ class StateReader
22
22
  end
23
23
 
24
24
  def state_count
25
- dummy_dirs_current_and_parent = 2
26
- Dir.new(@filename_formatter.session_dir @session_id).count - dummy_dirs_current_and_parent
25
+ @shell.real_dir_entries(@filename_formatter.session_dir @session_id).count
27
26
  end
28
27
 
29
28
  def enough_states?
@@ -0,0 +1,57 @@
1
+ require 'uploader'
2
+
3
+ class UploadCommand
4
+
5
+ PROPERTY_FILENAME = '.meta'
6
+
7
+ attr_accessor :uploader
8
+
9
+ def initialize shell, view, hostname
10
+ @shell = shell
11
+ @view = view
12
+ @hostname = hostname
13
+ @uploader = Uploader.new(hostname, '', '')
14
+ end
15
+
16
+ def execute
17
+ upload nil, nil
18
+ end
19
+
20
+ def execute_from_shell params
21
+ upload params[1]
22
+ end
23
+
24
+ def upload session_directory, open_browser=true
25
+ formatter = FilenameFormatter.new
26
+ framework = framework_property
27
+ if not session_directory then
28
+ session_directory = formatter.session_dir @shell.newest_dir_entry(FilenameFormatter.codersdojo_workspace)
29
+ end
30
+ @view.show_upload_start session_directory, @hostname, framework
31
+ @uploader.framework = framework
32
+ @uploader.session_dir = session_directory
33
+ upload_result = @uploader.upload
34
+ @view.show_upload_result upload_result
35
+ url = upload_result.split.last
36
+ if open_browser then
37
+ @shell.open_with_default_app url
38
+ end
39
+ end
40
+
41
+ def command_key
42
+ 'u'
43
+ end
44
+
45
+ def accepts_shell_command? command
46
+ command == 'upload'
47
+ end
48
+
49
+ def framework_property
50
+ properties['framework']
51
+ end
52
+
53
+ def properties
54
+ @shell.read_properties PROPERTY_FILENAME
55
+ end
56
+
57
+ end
@@ -0,0 +1,19 @@
1
+ class UploadNoOpenCommand
2
+
3
+ def initialize upload_command
4
+ @upload_command = upload_command
5
+ end
6
+
7
+ def execute_from_shell params
8
+ upload params[1]
9
+ end
10
+
11
+ def upload session_directory
12
+ @upload_command.upload session_directory, false
13
+ end
14
+
15
+ def accepts_shell_command? command
16
+ command == 'upload-no-open'
17
+ end
18
+
19
+ end
data/app/uploader.rb CHANGED
@@ -4,11 +4,13 @@ require 'progress'
4
4
  require 'filename_formatter'
5
5
  require 'xml_element_extractor'
6
6
  require 'rest_client'
7
+ require 'shell_wrapper'
7
8
 
8
9
  class Uploader
9
10
 
10
11
  attr_reader :states
11
-
12
+ attr_accessor :framework
13
+
12
14
  def initialize hostname, framework, session_dir, state_reader = StateReader.new(ShellWrapper.new)
13
15
  @states = []
14
16
  @hostname = hostname
@@ -17,6 +19,10 @@ class Uploader
17
19
  @state_reader.session_dir = session_dir
18
20
  end
19
21
 
22
+ def session_dir= dir
23
+ @state_reader.session_dir = dir
24
+ end
25
+
20
26
  def upload
21
27
  return upload_kata_and_states if @state_reader.enough_states?
22
28
  return "You need at least two states"
@@ -6,4 +6,4 @@ These files were created:
6
6
  Run run-endless.%sh% and start your kata. (On Mac/Linux you have to call ./run-endless.%sh%.)
7
7
 
8
8
  Assumptions:
9
- - The whole kata source code is in the one %kata_file%.js.
9
+ - The whole kata source code is in the one spec.js.
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codersdojo
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 2
9
- - 8
10
- version: 1.2.08
9
+ - 9
10
+ version: 1.2.09
11
11
  platform: ruby
12
12
  authors:
13
13
  - CodersDojo-Team
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-28 00:00:00 +02:00
18
+ date: 2011-05-05 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -62,8 +62,9 @@ files:
62
62
  - app/argument_parser.rb
63
63
  - app/codersdojo.rb
64
64
  - app/console_view.rb
65
- - app/controller.rb
66
65
  - app/filename_formatter.rb
66
+ - app/generate_command.rb
67
+ - app/help_command.rb
67
68
  - app/info_property_file.rb
68
69
  - app/progress.rb
69
70
  - app/property_file_missing_exception.rb
@@ -74,10 +75,13 @@ files:
74
75
  - app/shell_argument_exception.rb
75
76
  - app/shell_process.rb
76
77
  - app/shell_wrapper.rb
78
+ - app/start_command.rb
77
79
  - app/state.rb
78
80
  - app/state_reader.rb
79
81
  - app/text_converter.rb
80
82
  - app/text_template_machine.rb
83
+ - app/upload_command.rb
84
+ - app/upload_no_open_command.rb
81
85
  - app/uploader.rb
82
86
  - app/xml_element_extractor.rb
83
87
  - templates/any/README
data/app/controller.rb DELETED
@@ -1,84 +0,0 @@
1
- require 'scheduler'
2
- require 'uploader'
3
- require 'filename_formatter'
4
-
5
- class Controller
6
-
7
- def initialize shell, view, scaffolder, hostname
8
- @property_filename = '.meta'
9
- @shell = shell
10
- @view = view
11
- @scaffolder = scaffolder
12
- @hostname = hostname
13
- @filename_formatter = FilenameFormatter.new
14
- end
15
-
16
- def help command=nil
17
- if command then
18
- @view.show_detailed_help command.downcase
19
- else
20
- @view.show_help
21
- end
22
- end
23
-
24
- def generate framework, kata_file
25
- if not kata_file then
26
- @view.show_missing_command_argument_error "setup", "kata_file"
27
- return
28
- end
29
- begin
30
- @scaffolder.scaffold framework, kata_file
31
- @view.show "\n" + @shell.read_file("README")
32
- rescue
33
- @view.show_unknown_framework_error framework, @scaffolder.list_templates
34
- end
35
- end
36
-
37
- def start command, file
38
- if not command or not file then
39
- @view.show_missing_command_argument_error "start"
40
- return
41
- end
42
- @view.show_start_kata command, file, framework_property
43
- dojo = Runner.new @shell, SessionIdGenerator.new
44
- dojo.file = file
45
- dojo.run_command = command
46
- scheduler = Scheduler.new dojo, @view
47
- scheduler.start
48
- if scheduler.last_action_was_upload? then
49
- upload nil
50
- end
51
- end
52
-
53
- # merge with 'upload_with_framework' when the framework parameter is removed
54
- def upload session_directory, open_browser=true
55
- upload_with_framework framework_property, session_directory, open_browser
56
- end
57
-
58
- # framework parameter is obsolete since client version 1.1.08 (08-feb-2011)
59
- # it stays here for compatibility reasons and will be removed in the near future
60
- def upload_with_framework framework, session_directory , open_browser=true
61
- formatter = FilenameFormatter.new
62
- if not session_directory then
63
- session_directory = formatter.session_dir @shell.newest_dir_entry(FilenameFormatter.codersdojo_workspace)
64
- end
65
- @view.show_upload_start session_directory, @hostname, framework
66
- uploader = Uploader.new @hostname, framework, session_directory
67
- upload_result = uploader.upload
68
- @view.show_upload_result upload_result
69
- url = upload_result.split.last
70
- if open_browser then
71
- @shell.open_with_default_app url
72
- end
73
- end
74
-
75
- def framework_property
76
- properties['framework']
77
- end
78
-
79
- def properties
80
- @shell.read_properties @property_filename
81
- end
82
-
83
- end
84
-