Class: Widow::Exclude

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

Instance Method Summary collapse

Constructor Details

#initialize(root_dir, logger) ⇒ Exclude

Returns a new instance of Exclude.



124
125
126
127
128
129
130
131
132
133
# File 'lib/widow.rb', line 124

def initialize root_dir, logger
	@patterns = Pathname.glob("#{root_dir}/**/.widowignore").map do |file|
		next [file, File.readlines(file)]
	end.to_h.map do |file, lines|
		lines.map do |line|
			/^#{file.dirname}\/#{line.sub /\s*$/, ''}/ unless line =~ /^\s*$/
		end.compact
	end.flatten(1) << /.*\/\.widowignore$/
	logger.info "ignoring:\n#{to_s}"
end

Instance Method Details

#ignored?(file) ⇒ Boolean

Returns:

  • (Boolean)


135
136
137
138
139
# File 'lib/widow.rb', line 135

def ignored? file
	return @patterns.any? do |pattern|
		file.to_s =~ pattern
	end
end

#ignored_patternsObject



141
142
143
# File 'lib/widow.rb', line 141

def ignored_patterns
	return @patterns.map &:to_s
end

#to_sObject



145
146
147
# File 'lib/widow.rb', line 145

def to_s
	return ignored_patterns.join "\n"
end