Class: Guard::Rake

Inherits:
Plugin
  • Object
show all
Defined in:
lib/guard/rake.rb

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Rake

Returns a new instance of Rake.



11
12
13
14
15
16
17
18
19
# File 'lib/guard/rake.rb', line 11

def initialize(options={})
  super
  @options = {
    :run_on_start => true,
    :run_on_all => true,
    :task_args => []
  }.update(options)
  @task = @options[:task]
end

Class Attribute Details

.rakefile_loadedObject

Returns the value of attribute rakefile_loaded.



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

def rakefile_loaded
  @rakefile_loaded
end

Instance Method Details

#load_rakefileObject



71
72
73
74
75
76
# File 'lib/guard/rake.rb', line 71

def load_rakefile
  ARGV.clear
  ::Rake.application.init
  ::Rake.application.load_rakefile
  self.class.rakefile_loaded = true
end

#reloadObject



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

def reload
  stop
  start
end

#run_allObject



38
39
40
# File 'lib/guard/rake.rb', line 38

def run_all
  run_rake_task if @options[:run_on_all]
end

#run_on_change(paths) ⇒ Object



43
44
45
# File 'lib/guard/rake.rb', line 43

def run_on_change(paths)
  run_rake_task(paths)
end

#run_on_modifications(paths) ⇒ Object



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

def run_on_modifications(paths)
  run_rake_task(paths)
end

#run_rake_task(paths = []) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/guard/rake.rb', line 52

def run_rake_task(paths=[])
  UI.info "running #{@task}"
  ::Rake::Task.tasks.each { |t| t.reenable }
  ::Rake::Task[@task].invoke(*@options[:task_args], paths)

  Notifier.notify(
    "watched files: #{paths}",
    :title => "running rake task: #{@task}",
    :image => :success
  )
rescue Exception => e
  UI.error "#{self.class.name} failed to run rake task <#{@task}>, exception was:\n\t#{e.class}: #{e.message}"
  UI.debug "\n#{e.backtrace.join("\n")}"

  Notifier.notify(
    " #{e.class}: #{e.message}", :title => "fail to run rake task: #{@task}", :image => :failed)
  throw :task_has_failed
end

#startObject



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

def start
  UI.info "Starting guard-rake #{@task}"
  load_rakefile unless self.class.rakefile_loaded
  run_rake_task if @options[:run_on_start]
  true
end

#stopObject



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

def stop
  UI.info "Stopping guard-rake #{@task}"
  true
end