lib/isolator/ignorer.rb in isolator-0.8.0 vs lib/isolator/ignorer.rb in isolator-0.9.0

- old
+ new

@@ -1,19 +1,34 @@ # frozen_string_literal: true module Isolator # Handle ignoring isolator errors using a yml file class Ignorer - TODO_PATH = ".isolator_todo.yml" + class ParseError < StandardError + def initialize(file_path, klass) + @file_path = file_path + @klass = klass + end + def message + "Unable to parse ignore config file #{@file_path}. Expected Hash, got #{@klass}." + end + end + class << self - def prepare(path: TODO_PATH, regex_string: "^.*(#ignores#):.*$") + def prepare(path:, regex_string: "^.*(#ignores#):.*$") return unless File.exist?(path) - todos = YAML.load_file(path) + ignores = begin + YAML.load_file(path, aliases: true) + rescue ArgumentError # support for older rubies https://github.com/rails/rails/commit/179d0a1f474ada02e0030ac3bd062fc653765dbe + YAML.load_file(path) + end + raise ParseError.new(path, ignores.class) unless ignores.respond_to?(:fetch) + Isolator.adapters.each do |id, adapter| - ignored_paths = todos.fetch(id, []) + ignored_paths = ignores.fetch(id, []) AdapterIgnore.new(adapter: adapter, ignored_paths: ignored_paths, regex_string: regex_string).prepare end end end