class Xccoveralls::Ignorefile

Constants

COMMENT_OR_WHITESPACE

Attributes

statements[R]

Public Class Methods

new(*args) click to toggle source
# File lib/xccoveralls/ignorefile.rb, line 12
def initialize(*args)
  @statements = []

  args.each do |arg|
    !arg.is_a?(Array) && File.exist?(arg) &&
      (return load_file(arg))
    push(arg)
  end
end

Public Instance Methods

<<(*arg)
Alias for: push
apply(files) click to toggle source
# File lib/xccoveralls/ignorefile.rb, line 55
def apply(files)
  files.reject { |file| ignored?(file) }
end
apply!(files) click to toggle source
# File lib/xccoveralls/ignorefile.rb, line 59
def apply!(files)
  files.reject! { |file| ignored?(file) }
end
ignored?(file) click to toggle source
# File lib/xccoveralls/ignorefile.rb, line 40
def ignored?(file) # rubocop:disable Metrics/AbcSize
  return true if file.to_s.strip.empty?

  path = Pathname.new file

  includes = statements.reject { |statement| statement[0] == '!' }
                       .map { |statement| "*#{statement}*" }

  excludes = statements.select { |statement| statement[0] == '!' }
                       .map { |statement| "*#{statement[1..-1]}*" }

  includes.any? { |statement| path.fnmatch?(statement) } &&
    excludes.all? { |statement| !path.fnmatch?(statement) }
end
load_file(file) click to toggle source
# File lib/xccoveralls/ignorefile.rb, line 29
def load_file(file)
  file = Pathname.new(file)
  return unless file.exist?

  push(file.readlines.map(&:strip).reject do |line|
    line.empty? || line =~ COMMENT_OR_WHITESPACE
  end)

  self
end
push(*arg) click to toggle source
# File lib/xccoveralls/ignorefile.rb, line 22
def push(*arg)
  statements.push(*arg.flatten.map(&:strip))

  self
end
Also aliased as: <<