Permalink
Browse files

refactoring out into pieces

  • Loading branch information...
1 parent a85b154 commit a227481fa2b3eddf31fde14b25cce35dfa7ad615 @guilhermesilveira guilhermesilveira committed Apr 6, 2011
Showing with 72 additions and 33 deletions.
  1. +1 −1 bin/vraptor
  2. +3 −31 lib/vraptor-scaffold.rb
  3. +67 −0 lib/vraptor-scaffold/execution.rb
  4. +1 −1 lib/vraptor-scaffold/version.rb
View
@@ -3,5 +3,5 @@
require File.dirname(__FILE__) + '/../lib/vraptor-scaffold'
begin
- VraptorScaffold.execute(ARGV.dup)
+ VraptorScaffold::Execution.new.run(ARGV.dup)
end
@@ -1,33 +1,5 @@
-require File.dirname(__FILE__) + '/vraptor-scaffold/load_paths'
-
module VraptorScaffold
- def self.execute(args)
- action = args.shift
- print_help(AppGenerator) if help? action
- run_app_generator(args.shift, args) if action == "new"
- run_scaffold_generator(args) if action == "scaffold"
- end
-
- def self.run_app_generator(project_path, args)
- print_help(AppGenerator) if help? project_path
- AppGenerator.new(project_path, args).invoke_all
- end
+end
- def self.run_scaffold_generator(args)
- print_help(ScaffoldGenerator) if help? args.first
- unless File.exist?("src")
- puts "To run vraptor scaffold please go to the project root folder."
- Kernel::exit
- end
- ScaffoldGenerator.new(args).invoke_all
- end
-
- def self.print_help(generator)
- generator.start(["-h"])
- Kernel::exit
- end
-
- def self.help?(command)
- [nil, "-h", "--help"].include?(command)
- end
-end
+require File.dirname(__FILE__) + '/vraptor-scaffold/execution.rb'
+require File.dirname(__FILE__) + '/vraptor-scaffold/load_paths'
@@ -0,0 +1,67 @@
+module VraptorScaffold
+
+ module Runner
+
+ class Help
+
+ def run(args)
+ AppGenerator.start(["-h"])
+ end
+
+ def self.help?(arg)
+ [nil, "-h", "--help"].include?(arg)
+ end
+
+ end
+
+ class Scaffold
+ def run(args)
+ if VraptorScaffold::Runner::Help.help? args.first
+ ScaffoldGenerator.start(["-h"])
+ elsif File.exist?("src")
+ ScaffoldGenerator.new(args).invoke_all
+ else
+ puts "To run vraptor scaffold please go to the project root folder."
+ end
+ end
+ end
+
+ class Generator
+ def run(args)
+ project_path = args.shift
+ if VraptorScaffold::Runner::Help.help? project_path
+ AppGenerator.start(["-h"])
+ else
+ AppGenerator.new(project_path, args).invoke_all
+ end
+ end
+ end
+
+ class CommandsHelp
+ def run(args)
+ puts "Available runners for vraptor are:"
+ puts VraptorScaffold::COMMANDS.inspect
+ end
+ end
+ end
+
+ class Execution
+
+ def run(args)
+ action = args.shift
+ runner_for(action).new.run(args)
+ end
+
+ def runner_for(action)
+ VraptorScaffold::COMMANDS.fetch(action, Runner::CommandsHelp)
+ end
+
+ end
+
+ COMMANDS = {"--help" => Runner::Help,
+ "-h" => Runner::Help,
+ "scaffold" => Runner::Scaffold,
+ "new" => Runner::Generator
+ }
+
+end
@@ -1,3 +1,3 @@
module VraptorScaffold
- VERSION = "1.2.0"
+ VERSION = "1.2.1"
end

0 comments on commit a227481

Please sign in to comment.