Skip to content

Commit

Permalink
refactoring out into pieces
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermesilveira committed Apr 6, 2011
1 parent a85b154 commit a227481
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 33 deletions.
2 changes: 1 addition & 1 deletion bin/vraptor
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
require File.dirname(__FILE__) + '/../lib/vraptor-scaffold'

begin
VraptorScaffold.execute(ARGV.dup)
VraptorScaffold::Execution.new.run(ARGV.dup)
end
34 changes: 3 additions & 31 deletions lib/vraptor-scaffold.rb
Original file line number Diff line number Diff line change
@@ -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'
67 changes: 67 additions & 0 deletions lib/vraptor-scaffold/execution.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion lib/vraptor-scaffold/version.rb
Original file line number Diff line number Diff line change
@@ -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.