Class: Drydock::IgnorefileDefinition

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/drydock/ignorefile_definition.rb

Defined Under Namespace

Classes: Rule

Instance Method Summary collapse

Constructor Details

#initialize(file_or_filename, dotfiles: false) ⇒ IgnorefileDefinition

Returns a new instance of IgnorefileDefinition.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/drydock/ignorefile_definition.rb', line 16

def initialize(file_or_filename, dotfiles: false)
  @dotfiles = dotfiles

  if file_or_filename.respond_to?(:readlines)
    patterns = Array(file_or_filename.readlines)
  else
    patterns = File.exist?(file_or_filename) ? File.readlines(file_or_filename) : []
  end

  @rules = patterns.map do |pattern|
    pattern = pattern.chomp
    if pattern.start_with?('!')
      Rule.new(pattern.slice(1..-1), true)
    else
      Rule.new(pattern, false)
    end
  end
end

Instance Method Details

#match?(filename) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
38
39
40
# File 'lib/drydock/ignorefile_definition.rb', line 35

def match?(filename)
  return false if excludes?(filename)
  return true if includes?(filename)
  return true if is_dotfile?(filename)
  return false
end