Sha256: 34144d5443cac860ff622d3c23edced11b326dc15e5cdc7a554db8501abe79fd

Contents?: true

Size: 1.58 KB

Versions: 1

Compression:

Stored size: 1.58 KB

Contents

require 'guard'
require 'guard/guard'
require 'guard/rails/runner'
require 'rbconfig'

module Guard
  class Rails < ::Guard::Guard
    attr_reader :options, :runner

    DEFAULT_OPTIONS = {
        :port => 3000,
        :environment => 'development',
        :start_on_start => true,
        :force_run => false,
        :timeout => 20,
        :server => nil
      }

    def initialize(watchers = [], options = {})
      super
      @options = DEFAULT_OPTIONS.merge(options)

      @runner = RailsRunner.new(@options)
    end

    def start
      server = options[:server] ? "#{options[:server]} and " : ""
      UI.info "Guard::Rails will now restart your app on port #{options[:port]} using #{server}#{options[:environment]} environment."
      run_all if options[:start_on_start]
    end

    def run_all
      UI.info "Restarting Rails..."
      Notifier.notify("Rails restarting on port #{options[:port]} in #{options[:environment]} environment...", :title => "Restarting Rails...", :image => :pending)
      if runner.restart
        UI.info "Rails restarted, pid #{runner.pid}"
        Notifier.notify("Rails restarted on port #{options[:port]}.", :title => "Rails restarted!", :image => :success)
      else
        UI.info "Rails NOT restarted, check your log files."
        Notifier.notify("Rails NOT restarted, check your log files.", :title => "Rails NOT restarted!", :image => :failed)
      end
    end

    def stop
      Notifier.notify("Until next time...", :title => "Rails shutting down.", :image => :pending)
      runner.stop
    end

    def run_on_change(paths)
      run_all
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
guard-rails-0.0.3 lib/guard/rails.rb