Class: Rake::LatherTask

Inherits:
TaskLib
  • Object
show all
Defined in:
lib/rake/lathertask.rb

Overview

Runs the target task any time a file matching one of the globs changes.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*globs) {|_self| ... } ⇒ LatherTask

Returns a new instance of LatherTask.

Yields:

  • (_self)

Yield Parameters:



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/rake/lathertask.rb', line 30

def initialize *globs, &block
  @options = Hash === globs.last ? globs.pop : {}
  @globs   = globs
  @target  = @options.delete(:target) || :test

  @changed = case @target
             when Rake::TestTask then handle_rake_test_task
             else lambda {}
             end

  yield self if block_given?

  @target = Rake::Task[@target]

  desc "Rinse and repeat"
  task :lather do
    watcher = Lather::Watcher.new @globs, @options do |changed|
      begin
        @changed[changed]
        @target.invoke
      rescue StandardError => e
        raise e unless e.to_s =~ /^Command failed/
      ensure
        reenable @target
      end
    end

    watcher.go!
  end
end

Instance Attribute Details

#globsObject

An array of globs to watch.



14
15
16
# File 'lib/rake/lathertask.rb', line 14

def globs
  @globs
end

#optionsObject

A hash of options, most of which are passed on to Lather::Watcher.



19
20
21
# File 'lib/rake/lathertask.rb', line 19

def options
  @options
end

#targetObject

The task to run when things change. Default is :test. If this is an instance of Rake::TestTask, the task’s file_list will be added to globs, and the TEST environment variable will be set to a glob of changed tests before each invocation.



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

def target
  @target
end

Instance Method Details

#changed(&block) ⇒ Object

Get and set the block called each time a file matching one of the globs changes. Default is lambda {}.



64
65
66
67
# File 'lib/rake/lathertask.rb', line 64

def changed &block
  return @changed unless block_given?
  @changed = block
end