Class: RuboCop::Cop::Generator::ConfigurationInjector

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/cop/generator/configuration_injector.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

TEMPLATE =
<<-YAML.strip_indent
             %<badge>s:
               Description: 'TODO: Write a description of the cop.'
               Enabled: true
               VersionAdded: '%<version_added>s'

YAML

Instance Method Summary collapse

Constructor Details

#initialize(configuration_file_path:, badge:, version_added:) ⇒ ConfigurationInjector

Returns a new instance of ConfigurationInjector.



18
19
20
21
22
23
# File 'lib/rubocop/cop/generator/configuration_injector.rb', line 18

def initialize(configuration_file_path:, badge:, version_added:)
  @configuration_file_path = configuration_file_path
  @badge = badge
  @version_added = version_added
  @output = output
end

Instance Method Details

#injectObject



25
26
27
28
29
30
31
32
# File 'lib/rubocop/cop/generator/configuration_injector.rb', line 25

def inject
  configuration_entries.insert(find_target_line,
                               new_configuration_entry)

  File.write(configuration_file_path, configuration_entries.join)

  yield if block_given?
end