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

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/cop/generator/configuration_injector.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

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 =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

<<~YAML
  %<badge>s:
    Description: 'TODO: Write a description of the cop.'
    Enabled: pending
    VersionAdded: '%<version_added>s'
YAML

Instance Method Summary collapse

Constructor Details

#initialize(configuration_file_path:, badge:, version_added: '<<next>>') ⇒ ConfigurationInjector

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ConfigurationInjector.


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

def initialize(configuration_file_path:, badge:, version_added: '<<next>>')
  @configuration_file_path = configuration_file_path
  @badge = badge
  @version_added = version_added
  @output = output
end

Instance Method Details

#injectObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


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

def inject
  target_line = find_target_line
  if target_line
    configuration_entries.insert(target_line, "#{new_configuration_entry}\n")
  else
    configuration_entries.push("\n#{new_configuration_entry}")
  end

  File.write(configuration_file_path, configuration_entries.join)

  yield if block_given?
end