Class: Driskell::Listen::Silencer

Inherits:
Object
  • Object
show all
Defined in:
lib/driskell-listen/silencer.rb,
lib/driskell-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
DEFAULT_IGNORED_EXTENSIONS =

The default list of files that get ignored.

/(?:
  # 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}
     )
    )

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSilencer

Returns a new instance of Silencer.



57
58
59
# File 'lib/driskell-listen/silencer.rb', line 57

def initialize
  configure({})
end

Instance Attribute Details

#ignore_patternsObject

Returns the value of attribute ignore_patterns.



55
56
57
# File 'lib/driskell-listen/silencer.rb', line 55

def ignore_patterns
  @ignore_patterns
end

#only_patternsObject

Returns the value of attribute only_patterns.



55
56
57
# File 'lib/driskell-listen/silencer.rb', line 55

def only_patterns
  @only_patterns
end

Instance Method Details

#configure(options) ⇒ Object



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

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)


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

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