-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This should help with instances where libraries are required before their extensions resulting in the extensions never getting loaded.
- Loading branch information
1 parent
7760939
commit b517cf0
Showing
3 changed files
with
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
module AmazingPrint | ||
## | ||
# Attempt to load extensions up to 3 times since this library may be required | ||
# before dependencies that we have extensions for. | ||
# | ||
class ExtLoader | ||
EXT_LOAD_ATTEMPT_LIMIT = 3 | ||
|
||
@load_attemps = 0 | ||
|
||
def self.call | ||
return if @load_attemps >= EXT_LOAD_ATTEMPT_LIMIT | ||
|
||
require_relative 'ext/mongo_mapper' if defined?(MongoMapper) | ||
require_relative 'ext/mongoid' if defined?(Mongoid) | ||
require_relative 'ext/nobrainer' if defined?(NoBrainer) | ||
require_relative 'ext/nokogiri' if defined?(Nokogiri) | ||
require_relative 'ext/ostruct' if defined?(OpenStruct) # rubocop:disable Style/OpenStructUse | ||
require_relative 'ext/ripple' if defined?(Ripple) | ||
require_relative 'ext/sequel' if defined?(Sequel) | ||
|
||
@load_attemps += 1 | ||
end | ||
end | ||
end |
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