Sha256: 2612ef12c12d0088279a4d9b4534b2eb92268e261ef2517b21e9efcdb4977037

Contents?: true

Size: 1.82 KB

Versions: 1

Compression:

Stored size: 1.82 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/initializers/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

1 entries across 1 versions & 1 rubygems

Version Path
spring-0.0.2 lib/spring/commands.rb