Class: Guard::Rack

Inherits:
Plugin
  • Object
show all
Defined in:
lib/guard/rack.rb,
lib/guard/rack/command.rb,
lib/guard/rack/custom_process.rb

Defined Under Namespace

Classes: Command, CustomProcess

Constant Summary collapse

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'
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Rack

Returns a new instance of Rack.



22
23
24
25
26
# File 'lib/guard/rack.rb', line 22

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

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/guard/rack.rb', line 8

def options
  @options
end

#runnerObject (readonly)

Returns the value of attribute runner.



8
9
10
# File 'lib/guard/rack.rb', line 8

def runner
  @runner
end

Instance Method Details

#reloadObject



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/guard/rack.rb', line 34

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

#run_on_changes(_paths) ⇒ Object



51
52
53
# File 'lib/guard/rack.rb', line 51

def run_on_changes(_paths)
  reload
end

#startObject



28
29
30
31
32
# File 'lib/guard/rack.rb', line 28

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

#stopObject



46
47
48
49
# File 'lib/guard/rack.rb', line 46

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