Class: Guard::Rails

Inherits:
Guard
  • Object
show all
Defined in:
lib/guard/rails.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{
  :CLI => nil,
  :daemon => false,
  :debugger => false,
  :environment => 'development',
  :force_runs => false,
  :pid_file => nil, # construct the filename based on options[:environment] on runtime
  :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(watchers = [], options = {}) ⇒ Rails

Returns a new instance of Rails.



29
30
31
32
33
34
# File 'lib/guard/rails.rb', line 29

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

  @runner = RailsRunner.new(@options)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



12
13
14
# File 'lib/guard/rails.rb', line 12

def options
  @options
end

#runnerObject (readonly)

Returns the value of attribute runner.



12
13
14
# File 'lib/guard/rails.rb', line 12

def runner
  @runner
end

Instance Method Details

#reload(action = "restart") ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/guard/rails.rb', line 42

def reload(action = "restart")
  action_cap = action.capitalize
  UI.info "#{action_cap}ing Rails..."
  Notifier.notify("Rails #{action}ing on port #{options[:port]} in #{options[:environment]} environment...", :title => "#{action_cap}ing Rails...", :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



60
61
62
# File 'lib/guard/rails.rb', line 60

def run_on_changes(paths)
  reload
end

#startObject



36
37
38
39
40
# File 'lib/guard/rails.rb', line 36

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."
  reload("start") if options[:start_on_start]
end

#stopObject



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

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