Skip to content

Commit

Permalink
Refactor to use \A \z instead of ^ $ in ignore regexp pattern.
Browse files Browse the repository at this point in the history
  • Loading branch information
zw963 authored and ColinDKelley committed Sep 6, 2021
1 parent 797eb33 commit 029d60e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -122,7 +122,7 @@ listener.stop # stop both listening to changes and processing them

### Ignore / ignore!

`Listen` ignores some directories and extensions by default (See DEFAULT_IGNORED_DIRECTORIES and DEFAULT_IGNORED_EXTENSIONS in Listen::Silencer).
`Listen` ignores some directories and extensions by default (See DEFAULT_IGNORED_FILES and DEFAULT_IGNORED_EXTENSIONS in Listen::Silencer).
You can add ignoring patterns with the `ignore` option/method or overwrite default with `ignore!` option/method.

``` ruby
Expand Down Expand Up @@ -157,7 +157,7 @@ All the following options can be set through the `Listen.to` after the directory

```ruby
ignore: [%r{/foo/bar}, /\.pid$/, /\.coffee$/] # Ignore a list of paths
# default: See DEFAULT_IGNORED_DIRECTORIES and DEFAULT_IGNORED_EXTENSIONS in Listen::Silencer
# default: See DEFAULT_IGNORED_FILES and DEFAULT_IGNORED_EXTENSIONS in Listen::Silencer

ignore!: %r{/foo/bar} # Same as ignore options, but overwrite default ignored paths.

Expand Down
21 changes: 11 additions & 10 deletions lib/listen/silencer.rb
Expand Up @@ -3,8 +3,8 @@
module Listen
class Silencer
# The default list of directories that get ignored.
DEFAULT_IGNORED_DIRECTORIES = %r{^(?:
\.git
DEFAULT_IGNORED_FILES = %r{\A(?:
\.git
| \.svn
| \.hg
| \.rbx
Expand All @@ -13,8 +13,12 @@ class Silencer
| vendor/bundle
| log
| tmp
|vendor/ruby
)(/|$)}x.freeze
| vendor/ruby
# emacs temp files
| \#.+\#
| \.\#.+
)(/|\z)}x.freeze

# The default list of files that get ignored.
DEFAULT_IGNORED_EXTENSIONS = %r{(?:
Expand All @@ -34,11 +38,8 @@ class Silencer
| \.swpx
| ^4913
# Emacs backup/swap files
| (?:\.\#.+|\#.+\#)
# Sed temporary files - but without actual words, like 'sedatives'
| (?:^
| (?:\A
sed
(?:
Expand All @@ -58,7 +59,7 @@ class Silencer
| \.DS_Store
| \.tmp
| ~
)$}x.freeze
)\z}x.freeze

# TODO: deprecate these mutators; use attr_reader instead
attr_accessor :only_patterns, :ignore_patterns
Expand Down Expand Up @@ -92,7 +93,7 @@ def _only?(path)
def _init_ignores(ignores, overrides)
patterns = []
unless overrides
patterns << DEFAULT_IGNORED_DIRECTORIES
patterns << DEFAULT_IGNORED_FILES
patterns << DEFAULT_IGNORED_EXTENSIONS
end

Expand Down

0 comments on commit 029d60e

Please sign in to comment.