<commit_before># Listen [![Build Status](https://secure.travis-ci.org/guard/listen.png?branch=master)](http://travis-ci.org/guard/listen)

Work in progress...

The Listen gem listens to file modifications and notifies you about the changes.

Here the API that should be implemented, feel free to give your feeback via [Listen issues](https://github.com/guard/listener/issues)

## Block API

### One dir

``` ruby
Listen.to(dir, filter: '**/*', ignore: paths) do |modified, added, removed|
  ...
end
```

### Multiple dir

``` ruby
Listen.to do
  path(dir1, filter: '**/*', ignore: paths) do |modified, added, removed|
    ...
  end
  path(dir2, filter: '**/*', ignore: paths) do |modified, added, removed|
    ...
  end
  ....
end
```

Question: if dir2 is a child of dir1 both path block will be call if a file inside dir2 is modified right?

## "Object" API

``` ruby
listen = Listen.to(dir)
listen.ignore('.git')
listen.filter('*.rb')
listen.modification(&on_modification)
listen.addition(&on_addition)
listen.removal(&on_removal)
listen.start # enter the run loop
listen.stop
```

### Chainable

``` ruby
Listen.to(dir).ignore('.git').filter('*.rb').modification(&on_modification).addition(&on_addition).removal(&on_removal).start # enter the run loop
```

### Multiple dir support available via Thread.

``` ruby
listen  = Listen.ignore('.git')
styles  = listen.to(dir1).filter('*.css').addition(&on_style_addition)
scripts = listen.to(dir2).filter('*.js').addition(&on_script_addition)

Thread.new { styles.start } # enter the run loop
Thread.new { scripts.start } # enter the run loop
```<commit_msg>Update README with implemented API [ci skip]<commit_after># Listen [![Build Status](https://secure.travis-ci.org/guard/listen.png?branch=master)](http://travis-ci.org/guard/listen)

**Work in progress... only polling implemented yet**

The Listen gem listens to file modifications and notifies you about the changes.

## TODO

- Add `rb-fsevent` support
- Add `rb-inotify` support
- Add `rb-fchange` support
- Add checksum comparaison support for file modification lower than 1 second. (like Guard)
- Improve API (if needed)

## Install

``` bash
gem install listen
```

## Usage

There are two ways you can use Listen.

1. call `Listen.to` with a path params, and define callbacks in a block.
3. create a `listener` object usable in an (ARel style) chainable way.

Feel free to give your feeback via [Listen issues](https://github.com/guard/listener/issues)

### Block API

#### One dir

``` ruby
Listen.to('dir/path/to/listen', filter: /.*\.rb/, ignore: '/ignored/path') do |modified, added, removed|
  # ...
end
```

### "Object" API

``` ruby
listener = Listen.to('dir/path/to/listen')
listener = listener.ignore('/ignored/path')
listener = listener.filter(/.*\.rb/)
listener = listener.change(&callback)
listener.start # enter the run loop
listener.stop
```

#### Chainable

``` ruby
Listen.to('dir/path/to/listen').ignore('/ignored/path').filter(/.*\.rb/).change(&callback).start # enter the run loop
```

#### Multiple listeners support available via Thread

``` ruby
listener = Listen.to(dir1).ignore('/ignored/path/')
styles   = listener.filter(/.*\.css/).change(&style_callback)
scripts  = listener.filter(/.*\.js/).change(&scripts_callback)

Thread.new { styles.start } # enter the run loop
Thread.new { scripts.start } # enter the run loop
```
{'fraction_non_alphanumeric': 0.16508030933967877, 'fraction_numerical': 0.003271861986912552, 'mean_word_length': 4.312796208530806, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3447165', 'n_tokens_mistral': 1090, 'n_tokens_neox': 1039, 'n_words': 313}