1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
module Spring
module Commands
class Rails
def call
ARGV.unshift command_name
load Dir.glob(::Rails.root.join("{bin,script}/rails")).first
end
def description
nil
end
end
class RailsConsole < Rails
def env(args)
args.first if args.first && !args.first.index("-")
end
def command_name
"console"
end
end
class RailsGenerate < Rails
def command_name
"generate"
end
end
class RailsDestroy < Rails
def command_name
"destroy"
end
end
class RailsRunner < Rails
def call
ARGV.replace extract_environment(ARGV).first
super
end
def env(args)
extract_environment(args).last
end
def command_name
"runner"
end
def extract_environment(args)
environment = nil
args = args.select.with_index { |arg, i|
case arg
when "-e"
false
when /--environment=(\w+)/
environment = $1
false
else
if i > 0 && args[i - 1] == "-e"
environment = arg
false
else
true
end
end
}
[args, environment]
end
end
Spring.register_command "rails_console", RailsConsole.new
Spring.register_command "rails_generate", RailsGenerate.new
Spring.register_command "rails_destroy", RailsDestroy.new
Spring.register_command "rails_runner", RailsRunner.new
end
end
|