Class: Guard::Play

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

Instance Method Summary collapse

Constructor Details

#initialize(watchers = [], options = {}) ⇒ Play

Initialize a Guard.

Parameters:

  • watchers (Array<Guard::Watcher>) (defaults to: [])

    the Guard file watchers

  • options (Hash) (defaults to: {})

    the custom Guard options



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/guard/play.rb', line 10

def initialize(watchers = [], options = {})
  super
  @options = {
    :app_path       => '',
    :http_port      => 29000,  # NOT USE
    :jpda_port      => 28000   # NOT USE
  }.update(options)

  @last_failed  = false
  @app_path = @options[:app_path]
  @notify_title =  @app_path.empty? ? "Play!" : "Play! on #{@app_path}"
  @cmd_auto_test_deps = "cd #{@app_path}; play auto-test --deps; cd -"
  @cmd_auto_test = "cd #{@app_path}; play auto-test; cd -"
end

Instance Method Details

#reloadObject

Called when ‘reload|r|z + enter` is pressed. This method should be mainly used for “reload” (really!) actions like reloading passenger/spork/bundler/…

Raises:

  • (:task_has_failed)

    when reload has failed



41
42
# File 'lib/guard/play.rb', line 41

def reload
end

#run_allObject

Called when just ‘enter` is pressed This method should be principally used for long action like running all specs/tests/…

Raises:

  • (:task_has_failed)

    when run_all has failed



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

def run_all
  run_auto_test(@cmd_auto_test_deps)
end

#run_on_change(paths) ⇒ Object

Called on file(s) modifications that the Guard watches.

Parameters:

  • paths (Array<String>)

    the changes files or paths

Raises:

  • (:task_has_failed)

    when run_on_change has failed



54
55
56
# File 'lib/guard/play.rb', line 54

def run_on_change(paths)
  run_auto_test(@cmd_auto_test)
end

#run_on_deletion(paths) ⇒ Object

Called on file(s) deletions that the Guard watches.

Parameters:

  • paths (Array<String>)

    the deleted files or paths

Raises:

  • (:task_has_failed)

    when run_on_change has failed



61
62
63
# File 'lib/guard/play.rb', line 61

def run_on_deletion(paths)
  run_auto_test(@cmd_auto_test)
end

#startObject

Call once when Guard starts. Please override initialize method to init stuff.

Raises:

  • (:task_has_failed)

    when start has failed



27
28
29
30
# File 'lib/guard/play.rb', line 27

def start
  UI.info "Guard::Play is waiting to run auto-test..."
  run_all
end

#stopObject

Called when ‘stop|quit|exit|s|q|e + enter` is pressed (when Guard quits).

Raises:

  • (:task_has_failed)

    when stop has failed



34
35
36
# File 'lib/guard/play.rb', line 34

def stop
  UI.info "Guard::Play is stoped."
end