Class: RuboCop::FeatureLoader Private

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/feature_loader.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

This class handles loading files (a.k.a. features in Ruby) specified by --require command line option and require directive in the config.

Normally, the given string is directly passed to require. If a string beginning with . is given, it is assumed to be relative to the given directory.

If a string containing - is given, it will be used as is, but if we cannot find the file to load, we will replace - with / and try it again as when Bundler loads gems.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_directory_path:, feature:) ⇒ FeatureLoader

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of FeatureLoader.

Parameters:



27
28
29
30
# File 'lib/rubocop/feature_loader.rb', line 27

def initialize(config_directory_path:, feature:)
  @config_directory_path = config_directory_path
  @feature = feature
end

Class Method Details

.load(config_directory_path:, feature:) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:



20
21
22
# File 'lib/rubocop/feature_loader.rb', line 20

def load(config_directory_path:, feature:)
  new(config_directory_path: config_directory_path, feature: feature).load
end

Instance Method Details

#loadObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rubocop/feature_loader.rb', line 32

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