Class: Listen::Silencer

Inherits:
Object
  • Object
show all
Defined in:
lib/listen/silencer.rb,
lib/listen/silencer/controller.rb

Defined Under Namespace

Classes: Controller

Constant Summary collapse

DEFAULT_IGNORED_FILES =

The default list of directories that get ignored.

%r{\A(?:
    \.git
| \.svn
| \.hg
| \.rbx
| \.bundle
| bundle
| vendor/bundle
| log
| tmp
| vendor/ruby

# emacs temp files
| \#.+\#
| \.\#.+
)(/|\z)}x
DEFAULT_IGNORED_EXTENSIONS =

The default list of files that get ignored.

%r{(?:
  # Kate's tmp\/swp files
  \..*\d+\.new
  | \.kate-swp

  # Gedit tmp files
  | \.goutputstream-.{6}

  # Intellij files
  | ___jb_bak___
  | ___jb_old___

  # Vim swap files and write test
  | \.sw[px]
  | \.swpx
  | ^4913

  # Sed temporary files - but without actual words, like 'sedatives'
  | (?:\A
     sed

     (?:
      [a-zA-Z0-9]{0}[A-Z]{1}[a-zA-Z0-9]{5} |
      [a-zA-Z0-9]{1}[A-Z]{1}[a-zA-Z0-9]{4} |
      [a-zA-Z0-9]{2}[A-Z]{1}[a-zA-Z0-9]{3} |
      [a-zA-Z0-9]{3}[A-Z]{1}[a-zA-Z0-9]{2} |
      [a-zA-Z0-9]{4}[A-Z]{1}[a-zA-Z0-9]{1} |
      [a-zA-Z0-9]{5}[A-Z]{1}[a-zA-Z0-9]{0}
     )
    )

  # Mutagen sync temporary files
  | \.mutagen-temporary.*

  # other files
  | \.DS_Store
  | \.tmp
  | ~
)\z}x

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ Silencer

Returns a new instance of Silencer.



67
68
69
# File 'lib/listen/silencer.rb', line 67

def initialize(**options)
  configure(options)
end

Instance Attribute Details

#ignore_patternsObject

TODO: deprecate these mutators; use attr_reader instead



65
66
67
# File 'lib/listen/silencer.rb', line 65

def ignore_patterns
  @ignore_patterns
end

#only_patternsObject

TODO: deprecate these mutators; use attr_reader instead



65
66
67
# File 'lib/listen/silencer.rb', line 65

def only_patterns
  @only_patterns
end

Instance Method Details

#_ignore?(path) ⇒ Boolean (private)

Returns:

  • (Boolean)


85
86
87
# File 'lib/listen/silencer.rb', line 85

def _ignore?(path)
  ignore_patterns.any? { |pattern| path =~ pattern }
end

#_init_ignores(ignores, overrides) ⇒ Object (private)



93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/listen/silencer.rb', line 93

def _init_ignores(ignores, overrides)
  patterns = []
  unless overrides
    patterns << DEFAULT_IGNORED_FILES
    patterns << DEFAULT_IGNORED_EXTENSIONS
  end

  patterns << ignores
  patterns << overrides

  patterns.compact.flatten
end

#_only?(path) ⇒ Boolean (private)

Returns:

  • (Boolean)


89
90
91
# File 'lib/listen/silencer.rb', line 89

def _only?(path)
  only_patterns.any? { |pattern| path =~ pattern }
end

#configure(options) ⇒ Object

TODO: deprecate this mutator



72
73
74
75
# File 'lib/listen/silencer.rb', line 72

def configure(options)
  @only_patterns = options[:only] ? Array(options[:only]) : nil
  @ignore_patterns = _init_ignores(options[:ignore], options[:ignore!])
end

#silenced?(relative_path, type) ⇒ Boolean

Returns:

  • (Boolean)


77
78
79
80
81
# File 'lib/listen/silencer.rb', line 77

def silenced?(relative_path, type)
  path = relative_path.to_s # in case it is a Pathname

  _ignore?(path) || (only_patterns && type == :file && !_only?(path))
end