Sha256: 7c491eec1e2cefa1bb8c9241c028db7c16ec4d1643f80a7d0712ea1e68514506

Contents?: true

Size: 1.64 KB

Versions: 1

Compression:

Stored size: 1.64 KB

Contents

require 'guard'
require 'guard/plugin'
require 'guard/rack/runner'
require 'rbconfig'

module Guard
  class Rack < ::Guard::Plugin
    attr_reader :options, :runner

    DEFAULT_OPTIONS = {
      port:           9292,
      host:           '0.0.0.0',
      environment:    'development',
      start_on_start: true,
      force_run:      false,
      timeout:        20,
      debugger:       false,
      config:         'config.ru',
      cmd:            'rackup'
    }

    def initialize(options = {})
      super
      @options = DEFAULT_OPTIONS.merge(options)
      @runner = ::Guard::RackRunner.new(@options)
    end

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

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

    def stop
      Notifier.notify('Until next time...', title: 'Rack shutting down.', image: :pending)
      runner.stop
    end

    def run_on_changes(_paths)
      reload
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
guard-rack-2.2.0 lib/guard/rack.rb