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 ['"](.+)['"]/
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.
175 176 177 178 |
# File 'lib/rubocop/cop/generator.rb', line 175 def initialize(require_path) @require_path = require_path @require_entries = File.readlines(rubocop_root_file_path) end |
Instance Method Details
#inject ⇒ Object
180 181 182 183 184 |
# File 'lib/rubocop/cop/generator.rb', line 180 def inject return if require_exists? || !target_line File.write(rubocop_root_file_path, updated_directives) end |