jbarnette / lather

Lather rinses and repeats.

This URL has Read+Write access

jbarnette (author)
Tue Jun 23 01:24:43 -0700 2009
commit  99f3e368ecf1e86731ace3fc992a0ac659460b7a
tree    d86a79d6395151a148627ccc9fd69db689216d31
parent  f824f4b3710b220f79251894e7f23939438f59f5
lather /
name age message
file .gitignore Loading commit data...
file CHANGELOG.rdoc
file Manifest.txt
file README.rdoc
file Rakefile
directory bin/
directory lib/
directory test/
README.rdoc

Lather

Description

Lather is an easy way to watch files and do something when they change. By default, it checks for changes every second.

Examples

From the Command Line

The lather command-line tool lets you quickly track changes to a set of files.

    $ lather 'test/**/*_test.rb'

By default, lather will print a message each time a file matching your spec changes. ** is supported for recursive globbing, but make sure to escape/quote the glob so your shell doesn’t expand it.

You can also run a command every time something changes:

    $ lather -r 'rake test' '{lib,test}/**/*.rb'

From Code

    require "lather"

    watcher = Lather::Watcher.new "**/*.rb" do |changed|
      puts "Files changed: #{changed.join(' ')}"
    end

    watcher.go!

If you want to mess with the polling interval:

    # :sleep is in seconds
    Lather::Watcher.new "*.rb", :sleep => 5

From a Rakefile

    require "rake/lathertask"

    Rake::LatherTask.new "lib/**/*.rb" do |l|
      l.target = :something
      l.globs << "ext/**/*.{c,h}"
    end

This creates a lather task, which will call the target task any time the globs change. The block is optional: target defaults to :test.

If target is set to an instance of Rake::TestTask, some special behavior is enabled: Lather will add the test task’s file list to globs, and will set the TEST environment variable to the list of tests that need to be run.

    require "rake/testtask"
    require "rake/lathertask"

    test = Rake::TestTask.new do |t|
      t.libs << "test"
      t.pattern = "test/**/*_test.rb"
    end

    Rake::LatherTask.new "lib/**/*.rb", :target => test

The heuristic is really simple: If lib/foo.rb changes, any test whose path contains `foo` will be run. There’s no tracking of failures or single test runs. If you want more than this, you should be using Autotest.

Installation

    $ gem install lather

TODO

  • A way to get at the list of changed files in a -r command.
  • Some default exclude (like backup/editor files, .svn, .git) patterns, and an easy way to add new ones.
  • A —sleep <secs> switch for the command-line tool.

Thanks

Lather owes a huge debt to Ryan Davis’ ZenTest library, specifically autotest. Use it. See also Mike Clark and Geoffrey Grosenbach’s rstakeout, and a bunch of similar I’ve forgotten.

License

Copyright 2009 John Barnette (jbarnette@rubyforge.org)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.