Class: RuboCop::Cop::Generator::ConfigurationInjector
- Inherits:
-
Object
- Object
- RuboCop::Cop::Generator::ConfigurationInjector
- 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 %<badge>s: Description: 'TODO: Write a description of the cop.' Enabled: pending VersionAdded: '%<version_added>s' YAML
Instance Method Summary collapse
-
#initialize(configuration_file_path:, badge:, version_added:) ⇒ ConfigurationInjector
constructor
A new instance of ConfigurationInjector.
- #inject ⇒ Object
Constructor Details
#initialize(configuration_file_path:, badge:, version_added:) ⇒ ConfigurationInjector
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:) @configuration_file_path = configuration_file_path @badge = badge @version_added = version_added @output = output end |
Instance Method Details
#inject ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# 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 |