lib/spring/commands.rb in spring-0.0.4 vs lib/spring/commands.rb in spring-0.0.5

- old
+ new

@@ -3,14 +3,22 @@ class << self attr_reader :commands end - def self.register_command(name, klass) - commands[name] = klass.new + def self.register_command(name, klass, options = {}) + commands[name] = klass + + if options[:alias] + commands[options[:alias]] = klass + end end + def self.command_registered?(name) + commands.has_key?(name) + end + def self.command(name) commands.fetch name end # Load custom commands, if any @@ -33,11 +41,11 @@ def call(args) ARGV.replace args require File.expand_path(args.first) end end - Spring.register_command "test", Test + Spring.register_command "test", Test.new class RSpec def env "test" end @@ -49,11 +57,11 @@ def call(args) ::RSpec::Core::Runner.run(args) end end - Spring.register_command "rspec", RSpec + Spring.register_command "rspec", RSpec.new class Rake def setup require "rake" end @@ -61,11 +69,11 @@ def call(args) ARGV.replace args ::Rake.application.run end end - Spring.register_command "rake", Rake + Spring.register_command "rake", Rake.new class Console def setup require "rails/commands/console" end @@ -73,11 +81,11 @@ def call(args) ARGV.replace args ::Rails::Console.start(::Rails.application) end end - Spring.register_command "console", Console + Spring.register_command "console", Console.new, alias: "c" class Generate def setup Rails.application.load_generators end @@ -85,17 +93,17 @@ def call(args) ARGV.replace args require "rails/commands/generate" end end - Spring.register_command "generate", Generate + Spring.register_command "generate", Generate.new, alias: "g" class Runner def call(args) Object.const_set(:APP_PATH, Rails.root.join('config/application')) ARGV.replace args require "rails/commands/runner" end end - Spring.register_command "runner", Runner + Spring.register_command "runner", Runner.new, alias: "r" end end