Sha256: 0637011202a1ddde664a5a270b9a670aa243958d5fc18ec8eb2e61debaffac55

Contents?: true

Size: 1.77 KB

Versions: 1

Compression:

Stored size: 1.77 KB

Contents

# TODO: Need a way for applications to add their own commands.

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

  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.1 lib/spring/commands.rb