Class: Xcov::IgnoreHandler
- Inherits:
-
Object
- Object
- Xcov::IgnoreHandler
- Defined in:
- lib/xcov/ignore_handler.rb
Instance Attribute Summary collapse
-
#list ⇒ Object
Returns the value of attribute list.
Class Method Summary collapse
-
.read_ignore_file ⇒ Object
Static methods.
Instance Method Summary collapse
-
#initialize ⇒ IgnoreHandler
constructor
A new instance of IgnoreHandler.
-
#relative_path(path) ⇒ Object
Returns a relative path against ‘source_directory`.
- #should_ignore_file(filename) ⇒ Object
- #should_ignore_file_at_path(path) ⇒ Object
- #source_directory ⇒ Object
Constructor Details
#initialize ⇒ IgnoreHandler
Returns a new instance of IgnoreHandler.
7 8 9 10 11 |
# File 'lib/xcov/ignore_handler.rb', line 7 def initialize # We downcase ignored patterns in order to simulate a case-insensitive # comparison later @list = IgnoreHandler.read_ignore_file.map { |file| file.downcase } end |
Instance Attribute Details
#list ⇒ Object
Returns the value of attribute list.
5 6 7 |
# File 'lib/xcov/ignore_handler.rb', line 5 def list @list end |
Class Method Details
.read_ignore_file ⇒ Object
Static methods
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/xcov/ignore_handler.rb', line 36 def self.read_ignore_file require "yaml" ignore_file_path = Xcov.config[:ignore_file_path] ignore_list = [] begin ignore_list = YAML.load_file(ignore_file_path) rescue UI. "Skipping file blacklisting as no ignore file was found at path #{ignore_file_path}".yellow end return ignore_list end |
Instance Method Details
#relative_path(path) ⇒ Object
Returns a relative path against ‘source_directory`.
52 53 54 55 56 57 58 59 |
# File 'lib/xcov/ignore_handler.rb', line 52 def relative_path path require 'pathname' full_path = Pathname.new(path).realpath # /full/path/to/project/where/is/file.extension base_path = Pathname.new(source_directory).realpath # /full/path/to/project/ full_path.relative_path_from(base_path).to_s # where/is/file.extension end |
#should_ignore_file(filename) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/xcov/ignore_handler.rb', line 13 def should_ignore_file filename return false if @list.empty? # perform case-insensitive comparisons downcased_filename = filename.downcase return true if @list.include?(downcased_filename) # Evaluate possible regexs return @list.any? { |pattern| downcased_filename =~ Regexp.new("#{pattern}$") } end |
#should_ignore_file_at_path(path) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/xcov/ignore_handler.rb', line 24 def should_ignore_file_at_path path # Ignore specific files filename = File.basename(path) return true if should_ignore_file(filename) # Also ignore the files from ignored folders relative = relative_path(path).downcase return @list.any? { |ignored_path| relative.start_with? ignored_path } end |