Class: RuboCop::Cop::Rubomatic::Generator::DeptReadmeInjector

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

Direct Known Subclasses

CopReadmeInjector

Constant Summary collapse

TEMPLATE =
'* xref:./docs/cops/%{department_folder}/README.adoc[``%{department}``]'

Instance Method Summary collapse

Constructor Details

#initialize(readme_file_path:, badge:, department:) ⇒ DeptReadmeInjector

:nodoc:



11
12
13
14
15
16
# File 'lib/rubocop/cop/rubomatic/generator/dept_readme_injector.rb', line 11

def initialize(readme_file_path:, badge:, department:)
  @readme_file_path = readme_file_path
  @badge = badge
  @department = department
  @output = output
end

Instance Method Details

#inject_stringvoid

This method returns an undefined value.

Performs the actual string injection into the file modified version of ‘inject` from RuboCop::Cop::Generator::ConfigurationInjector Named `inject_string` becuase rubocop thought when called it was `Array#inject`



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

def inject_string
  target_line = find_target_line

  if target_line
    readme_entries.insert(target_line, "#{new_readme_entry}\n")
  else
    readme_entries.push(new_readme_entry)
  end

  File.write(readme_file_path, readme_entries.join(''))

  yield if block_given?
end