Class: RubomaticHtml::Generator::DeptReadmeInjector

Inherits:
Object
  • Object
show all
Defined in:
lib/rubomatic-html/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:



9
10
11
12
13
14
# File 'lib/rubomatic-html/generator/dept_readme_injector.rb', line 9

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`



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

def inject_string
  if readme_entries.none?("#{new_readme_entry}\n")
    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
  end

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

  yield if block_given?
end