class RuboCop::FeatureLoader
@api private
again as when Bundler loads gems.
cannot find the file to load, we will replace ‘-` with `/` and try it
If a string containing `-` is given, it will be used as is, but if we
directory.
beginning with `.` is given, it is assumed to be relative to the given
Normally, the given string is directly passed to `require`. If a string
by `–require` command line option and `require` directive in the config.
This class handles loading files (a.k.a. features in Ruby) specified
def initialize(config_directory_path:, feature:)
-
feature
(String
) -- -
config_directory_path
(String
) --
def initialize(config_directory_path:, feature:) @config_directory_path = config_directory_path @feature = feature end
def load(config_directory_path:, feature:)
-
feature
(String
) -- -
config_directory_path
(String
) --
def load(config_directory_path:, feature:) new(config_directory_path: config_directory_path, feature: feature).load end
def load
def load # Don't use `::Kernel.require(target)` to prevent the following error: # https://github.com/rubocop/rubocop/issues/10893 require(target) rescue ::LoadError => e raise if e.path != target begin # Don't use `::Kernel.require(target)` to prevent the following error: # https://github.com/rubocop/rubocop/issues/10893 require(namespaced_target) rescue ::LoadError => error_for_namespaced_target # NOTE: This wrap is necessary due to JRuby 9.3.4.0 incompatibility: # https://github.com/jruby/jruby/issues/7316 raise LoadError, e if error_for_namespaced_target.path == namespaced_target raise error_for_namespaced_target end end
def namespaced_feature
-
(String)
-
def namespaced_feature @feature.tr('-', '/') end
def namespaced_target
-
(String)
-
def namespaced_target if relative? relative(namespaced_feature) else namespaced_feature end end
def relative(feature)
-
(String)
-
Parameters:
-
(
String
) --
def relative(feature) ::File.join(@config_directory_path, feature) end
def relative?
-
(Boolean)
-
def relative? @feature.start_with?('.') end
def seems_cannot_load_such_file_error?(error)
-
(Boolean)
-
Parameters:
-
error
(LoadError
) --
def seems_cannot_load_such_file_error?(error) error.path == target end
def target
-
(String)
-
def target if relative? relative(@feature) else @feature end end