Class: Guard::Rails

Inherits:
Plugin
  • Object
show all
Defined in:
lib/guard/rails.rb,
lib/guard/rails/runner.rb

Defined Under Namespace

Classes: Runner

Constant Summary collapse

DEFAULT_OPTIONS =
{
  CLI: nil,
  daemon: false,
  debugger: false,
  environment: 'development',
  force_run: false,
  pid_file: nil, # construct the filename based on options[:environment] on runtime
  host: "localhost",
  port: 3000,
  server: nil, # specified by rails
  start_on_start: true,
  timeout: 30,
  zeus_plan: 'server',
  zeus: false,
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Rails

Returns a new instance of Rails.


25
26
27
28
29
30
# File 'lib/guard/rails.rb', line 25

def initialize(options = {})
  super
  @options = DEFAULT_OPTIONS.merge(options)

  @runner = Runner.new(@options)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options


7
8
9
# File 'lib/guard/rails.rb', line 7

def options
  @options
end

#runnerObject (readonly)

Returns the value of attribute runner


7
8
9
# File 'lib/guard/rails.rb', line 7

def runner
  @runner
end

Instance Method Details

#reload(action = "restart") ⇒ Object


37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/guard/rails.rb', line 37

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

#run_on_changes(paths) ⇒ Object Also known as: run_on_change


55
56
57
# File 'lib/guard/rails.rb', line 55

def run_on_changes(paths)
  reload
end

#startObject


32
33
34
35
# File 'lib/guard/rails.rb', line 32

def start
  UI.info "[Guard::Rails] will start #{options[:server] || "the default web server"} on port #{options[:port]} in #{options[:environment]}."
  reload("start") if options[:start_on_start]
end

#stopObject


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

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