Sha256: 115d8be292238d10c96e115df6d6dfbf1b24a99e966d022a3c5bf527c97baa24

Contents?: true

Size: 1.81 KB

Versions: 2

Compression:

Stored size: 1.81 KB

Contents

class Spring
  @commands = {}

  class << self
    attr_reader :commands
  end

  def self.register_command(name, klass)
    commands[name] = klass.new
  end

  def self.command(name)
    commands.fetch name
  end

  # Load custom commands, if any
  begin
    require "./config/spring"
  rescue LoadError
  end

  module Commands
    class Test
      def env
        "test"
      end

      def setup
        $LOAD_PATH.unshift "test"
        require "test_helper"
      end

      def call(args)
        ARGV.replace args
        require File.expand_path(args.first)
      end
    end
    Spring.register_command "test", Test

    class RSpec
      def env
        "test"
      end

      def setup
        $LOAD_PATH.unshift "spec"
        require "spec_helper"
      end

      def call(args)
        ::RSpec::Core::Runner.run(args)
      end
    end
    Spring.register_command "rspec", RSpec

    class Rake
      def setup
        require "rake"
      end

      def call(args)
        ARGV.replace args
        ::Rake.application.run
      end
    end
    Spring.register_command "rake", Rake

    class Console
      def setup
        require "rails/commands/console"
      end

      def call(args)
        ARGV.replace args
        ::Rails::Console.start(::Rails.application)
      end
    end
    Spring.register_command "console", Console

    class Generate
      def setup
        Rails.application.load_generators
      end

      def call(args)
        ARGV.replace args
        require "rails/commands/generate"
      end
    end
    Spring.register_command "generate", Generate

    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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
spring-0.0.4 lib/spring/commands.rb
spring-0.0.3 lib/spring/commands.rb