Created
September 2, 2011 20:12
-
-
Save douhashi/1189753 to your computer and use it in GitHub Desktop.
setup tasks for application template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Setup < Thor | |
include Thor::Actions | |
APP_ROOT = File.dirname(__FILE__) + "../../../".freeze | |
PLUGINS = [:rspec, :cucumber, :simple_form, :devise].freeze | |
SUCCESS_NOTICE = <<-SUCCESS_TEXT | |
Successful install [[[Name]]]. | |
SUCCESS_TEXT | |
desc "all", "install all plugins." | |
def all | |
invoke :rspec | |
invoke :cucumber | |
invoke :spork | |
invoke :guard_rspec | |
invoke :guard_cucumber | |
invoke :simple_form | |
invoke :devise | |
end | |
PLUGINS.each do |name| | |
desc name, "install #{name}." | |
define_method(name) do |*args| | |
ARGV.shift | |
inside APP_ROOT do | |
__send__ :"before_#{name}", *args | |
command = "script/rails generate #{name}:install" | |
command += " #{@cmd_options}" unless @cmd_options.nil? | |
run command | |
@cmd_options = nil | |
__send__ :"after_#{name}", *args | |
say SUCCESS_NOTICE.gsub("[[[Name]]]", name.to_s), Thor::Shell::Color::GREEN | |
end | |
end | |
end | |
desc "guard_rspec", "" | |
def guard_rspec(*args) | |
run "guard init rspec" | |
end | |
desc "guard_cucumber", "" | |
def guard_cucumber(*args) | |
run "spork cucumber --bootstrap" | |
run "guard init cucumber" | |
end | |
desc "spork", "" | |
def spork(*args) | |
run "spork --bootstrap" | |
run "guard init spork" | |
end | |
private | |
def after_rspec(*args) | |
remove_file "spec/spec_helper.rb" | |
get "https://raw.github.com/gist/1188870", "spec/spec_helper.rb" | |
run "echo '--drb' >> .rspec" | |
end | |
def before_cucumber(*args) | |
@cmd_options = ask("cucumber options?(ex: ja --rspec --capybara): ") | |
end | |
def after_cucumber(*args) | |
end | |
def method_missing(action, *args) | |
if PLUGINS.include?(action.to_s.sub("before_", "").to_sym) | |
return | |
elsif PLUGINS.include?(action.to_s.sub("after_", "").to_sym) | |
return | |
else | |
super(action, *args) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment