Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Rails check more specific #447

Merged
merged 1 commit into from Feb 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/bullet.rb
Expand Up @@ -63,6 +63,10 @@ def enable?
!!@enable
end

def app_root
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also moved the logic to one method that can be shared. This way we're not duplicating code across bullet. I hope this was an ok change to make

(defined?(::Rails.root) ? Rails.root.to_s : Dir.pwd).to_s
end

def n_plus_one_query_enable?
enable? && !!@n_plus_one_query_enable
end
Expand Down Expand Up @@ -111,9 +115,8 @@ def clear_whitelist
def bullet_logger=(active)
if active
require 'fileutils'
root_path = (rails? ? Rails.root.to_s : Dir.pwd).to_s
FileUtils.mkdir_p(root_path + '/log')
bullet_log_file = File.open("#{root_path}/log/bullet.log", 'a+')
FileUtils.mkdir_p(app_root + '/log')
bullet_log_file = File.open("#{app_root}/log/bullet.log", 'a+')
bullet_log_file.sync = true
UniformNotifier.customized_logger = bullet_log_file
end
Expand Down
4 changes: 0 additions & 4 deletions lib/bullet/dependency.rb
Expand Up @@ -10,10 +10,6 @@ def active_record?
@active_record ||= defined? ::ActiveRecord
end

def rails?
@rails ||= defined? ::Rails
end

def active_record_version
@active_record_version ||= begin
if active_record40?
Expand Down
5 changes: 2 additions & 3 deletions lib/bullet/stack_trace_filter.rb
Expand Up @@ -5,12 +5,11 @@ module StackTraceFilter
VENDOR_PATH = '/vendor'

def caller_in_project
app_root = rails? ? Rails.root.to_s : Dir.pwd
vendor_root = app_root + VENDOR_PATH
vendor_root = Bullet.app_root + VENDOR_PATH
bundler_path = Bundler.bundle_path.to_s
select_caller_locations do |location|
caller_path = location_as_path(location)
caller_path.include?(app_root) && !caller_path.include?(vendor_root) && !caller_path.include?(bundler_path) ||
caller_path.include?(Bullet.app_root) && !caller_path.include?(vendor_root) && !caller_path.include?(bundler_path) ||
Bullet.stacktrace_includes.any? { |include_pattern| pattern_matches?(location, include_pattern) }
end
end
Expand Down