From ffa8484af692615d36c94f9a546c094375ea04e9 Mon Sep 17 00:00:00 2001 From: Shia Date: Mon, 2 Sep 2024 22:30:16 +0900 Subject: [PATCH] Add ignore_glob_patterns option --- CHANGELOG.md | 2 ++ README.md | 8 +++++++- lib/akainaa.rb | 11 ++++++++--- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 29d47dd..41403c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ ## [Unreleased] - Bug fix: nested method call won't handled +- Bug fix: Empty 302 response body on /akainaa/reset +- Feature: Add `ignore_glob_patterns` option to `Akainaa.start` method ## [0.1.2] - 2024-05-06 diff --git a/README.md b/README.md index 15660e5..a569f51 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,13 @@ Here is example: ```ruby require 'akainaa' -Akainaa.start(project_dir: File.expand_path(__dir__)) +Akainaa.start( + project_dir: File.expand_path(__dir__), + ignore_glob_patterns: %w[ + config/application.rb + config/initializers/*_initializer.rb + ], +) require_relative 'app' diff --git a/lib/akainaa.rb b/lib/akainaa.rb index 20cf721..6acc06b 100644 --- a/lib/akainaa.rb +++ b/lib/akainaa.rb @@ -10,11 +10,15 @@ module Akainaa class Error < StandardError; end class << self - attr_accessor :project_dir + attr_accessor :project_dir, :ignore_files - def start(project_dir:) + def start(project_dir:, ignore_glob_patterns: []) @project_dir = project_dir @project_dir += '/' unless @project_dir.end_with?('/') + ignore_files = ignore_glob_patterns.flat_map do |pattern| + Dir["#{@project_dir}#{pattern}"].to_a + end + @ignore_files = Set.new(ignore_files) Coverage.start(lines: true) end @@ -23,6 +27,7 @@ def peek_result Coverage .peek_result .select { |k, _v| k.start_with?(project_dir) } + .reject { |k, _v| ignore_files.member?(k) } .transform_keys { |k| k.sub(project_dir, '') } end @@ -48,7 +53,7 @@ def call(env) path = extract_path_from_query(env) Akainaa.reset - [302, { 'Location' => "/akainaa?path=#{path}" }, [html]] + [302, { 'Location' => "/akainaa?path=#{path}" }, []] else @app.call(env) end