Module: RuboCop::Cop::LazyLoader
| Relationships & Source Files | |
| Extension / Inclusion / Inheritance Descendants | |
|
Extended In:
| |
| Defined in: | lib/rubocop/cop/lazy_loader.rb |
Overview
Extend a department module with this module and call #register_cop to register the department’s cops with the global registry without loading their files until a cop class itself is needed:
register_cop :BarBaz, "#{__dir__}/foo/bar_baz"
end
end
end
Instance Method Summary
-
#register_cop(constant_name, path)
Registers a cop for lazy loading.
Instance Method Details
#register_cop(constant_name, path)
Registers a cop for lazy loading. The cop appears in the registry by name right away, but its file is loaded only when the cop class is needed, e.g. when the cop is enabled for an inspection run.
The path must be absolute so that loading does not depend on $LOAD_PATH and cannot resolve
to another RuboCop installation.
# File 'lib/rubocop/cop/lazy_loader.rb', line 30
def register_cop(constant_name, path) raise ArgumentError, "cop path must be absolute: #{path}" unless File.absolute_path?(path) autoload constant_name, path qualified_name = "#{name}::#{constant_name}" Registry.global.lazy_load(Badge.for(qualified_name), qualified_name) end