-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce BulletmarkRepairer::Thread to avoid to handle Thread directly
- Loading branch information
Showing
4 changed files
with
38 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails' | ||
|
||
module BulletmarkRepairer | ||
class Thread | ||
class << self | ||
def current | ||
touch | ||
end | ||
|
||
def add(name:, method_type:, args:) | ||
touch | ||
::Thread.current[:bulletmark_repaier_loaded_associations][name][method_type].add(args) | ||
end | ||
|
||
def clear | ||
::Thread.current[:bulletmark_repaier_loaded_associations] = nil | ||
end | ||
|
||
private | ||
|
||
def touch | ||
::Thread.current[:bulletmark_repaier_loaded_associations] ||= Hash.new do |hash, key| | ||
hash[key] = { includes: Set.new, eager_load: Set.new, preload: Set.new } | ||
end | ||
end | ||
end | ||
end | ||
end |