Class: Listen::Silencer

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

Constant Summary collapse

DEFAULT_IGNORED_DIRECTORIES =

The default list of directories that get ignored.

%r{^(?:
  \.git
  | \.svn
  | \.hg
  | \.rbx
  | \.bundle
  | bundle
  | vendor/bundle
  | log
  | tmp
  |vendor/ruby
)(/|$)}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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSilencer

Returns a new instance of Silencer.



43
44
45
# File 'lib/listen/silencer.rb', line 43

def initialize
  configure({})
end

Instance Attribute Details

#ignore_patternsObject

Returns the value of attribute ignore_patterns.



41
42
43
# File 'lib/listen/silencer.rb', line 41

def ignore_patterns
  @ignore_patterns
end

#only_patternsObject

Returns the value of attribute only_patterns.



41
42
43
# File 'lib/listen/silencer.rb', line 41

def only_patterns
  @only_patterns
end

#optionsObject (readonly, private)

Returns the value of attribute options.



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

def options
  @options
end

Instance Method Details

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



70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/listen/silencer.rb', line 70

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

  patterns << ignores
  patterns << overrides

  patterns.compact.flatten
end

#configure(options) ⇒ Object



47
48
49
50
# File 'lib/listen/silencer.rb', line 47

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

TODO: switch type and path places - and verify

Returns:

  • (Boolean)


56
57
58
59
60
61
62
63
64
# File 'lib/listen/silencer.rb', line 56

def silenced?(relative_path, type)
  path = relative_path.to_s

  if only_patterns && type == :file
    return true unless only_patterns.any? { |pattern| path =~ pattern }
  end

  ignore_patterns.any? { |pattern| path =~ pattern }
end