Skip to content

Commit

Permalink
change Bullet's feature enable logic
Browse files Browse the repository at this point in the history
  • Loading branch information
koya1616 committed Feb 25, 2025
1 parent 86654e7 commit 6dc2c90
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ Bullet.unused_eager_loading_enable = false
Bullet.counter_cache_enable = false
```

Note: When calling `Bullet.enable`, all other detectors are reset to their defaults (`true`) and need reconfiguring.

## Safe list

Sometimes Bullet may notify you of query problems you don't care to fix, or
Expand Down
24 changes: 20 additions & 4 deletions lib/bullet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ def raise=(should_raise)
].freeze

def enable=(enable)
@enable = @n_plus_one_query_enable = @unused_eager_loading_enable = @counter_cache_enable = enable
@enable = enable

@n_plus_one_query_enable = true if @n_plus_one_query_enable.nil?
@unused_eager_loading_enable = true if @unused_eager_loading_enable.nil?
@counter_cache_enable = true if @counter_cache_enable.nil?

if enable?
reset_safelist
Expand All @@ -90,15 +94,27 @@ def app_root
end

def n_plus_one_query_enable?
enable? && !!@n_plus_one_query_enable
enable? && default_n_plus_one_query_enable?
end

def unused_eager_loading_enable?
enable? && !!@unused_eager_loading_enable
enable? && default_unused_eager_loading_enable?
end

def counter_cache_enable?
enable? && !!@counter_cache_enable
enable? && default_counter_cache_enable?
end

def default_n_plus_one_query_enable?
!!@n_plus_one_query_enable
end

def default_unused_eager_loading_enable?
!!@unused_eager_loading_enable
end

def default_counter_cache_enable?
!!@counter_cache_enable
end

def stacktrace_includes
Expand Down

0 comments on commit 6dc2c90

Please sign in to comment.