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_DIRECTORIES =

The default list of directories that get ignored.

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSilencer

Returns a new instance of Silencer.


62
63
64
# File 'lib/listen/silencer.rb', line 62

def initialize
  configure({})
end

Instance Attribute Details

#ignore_patternsObject

Returns the value of attribute ignore_patterns


60
61
62
# File 'lib/listen/silencer.rb', line 60

def ignore_patterns
  @ignore_patterns
end

#only_patternsObject

Returns the value of attribute only_patterns


60
61
62
# File 'lib/listen/silencer.rb', line 60

def only_patterns
  @only_patterns
end

Instance Method Details

#configure(options) ⇒ Object


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

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)

75
76
77
78
79
# File 'lib/listen/silencer.rb', line 75

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

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