Skip to content

Commit

Permalink
Add ignore_glob_patterns option
Browse files Browse the repository at this point in the history
  • Loading branch information
riseshia committed Sep 2, 2024
1 parent 68a58c2 commit 33b225c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
11 changes: 8 additions & 3 deletions lib/akainaa.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
Expand Down

0 comments on commit 33b225c

Please sign in to comment.