Class: RuboCop::Cop::Generator::RequireFileInjector

Inherits:
Object
  • Object
show all
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

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

#injectObject



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