Class: RuboCop::Cop::Generator::RequireFileInjector
- Inherits:
-
Object
- Object
- RuboCop::Cop::Generator::RequireFileInjector
- Defined in:
- lib/rubocop/cop/generator.rb
Overview
A class that injects a require directive into the root RuboCop file. It looks for other directives that require files in the same (cop) namespace and injects the provided one in alpha
Constant Summary collapse
- REQUIRE_PATH =
/require_relative ['"](.+)['"]/
Instance Method Summary collapse
-
#initialize(require_path) ⇒ RequireFileInjector
constructor
A new instance of RequireFileInjector.
- #inject ⇒ Object
Constructor Details
#initialize(require_path) ⇒ RequireFileInjector
Returns a new instance of RequireFileInjector.
199 200 201 202 |
# File 'lib/rubocop/cop/generator.rb', line 199 def initialize(require_path) @require_path = require_path @require_entries = File.readlines(rubocop_root_file_path) end |
Instance Method Details
#inject ⇒ Object
204 205 206 207 208 |
# File 'lib/rubocop/cop/generator.rb', line 204 def inject return if require_exists? || !target_line File.write(rubocop_root_file_path, updated_directives) end |