Class: Codeowners::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/codeowners/generator.rb

Constant Summary collapse

DEFAULT_OUTPUT_PATH =
'.github/CODEOWNERS'
DEFAULT_HUMAN_OUTPUT_PATH =
'.github/CODEOWNERS-HUMAN'

Instance Method Summary collapse

Constructor Details

#initialize(definitions_file: DefinitionsFile.new, output_path: DEFAULT_OUTPUT_PATH, human_output_path: DEFAULT_HUMAN_OUTPUT_PATH) ⇒ Generator

Returns a new instance of Generator.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/codeowners/generator.rb', line 9

def initialize(
  definitions_file: DefinitionsFile.new,
  output_path: DEFAULT_OUTPUT_PATH,
  human_output_path: DEFAULT_HUMAN_OUTPUT_PATH
)
  @definitions_file = definitions_file
  @output_path = output_path
  @human_output_path = human_output_path
  @calculated_owners = []
  @all_features = []
end

Instance Method Details

#callObject



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

def call
  File.open(output_path, 'w') do |output_file|
    File.open(human_output_path, 'w') do |output_human_file|
      @output_file = output_file
      @output_human_file = output_human_file

      output(blurb, depth: 0)
      calculate_owners_and_output_in_human_format(features: top_level_features)
      validate_owners_in_features
      output_in_machine_format
    end
  end
ensure
  @output_file = nil
  @output_human_file = nil
end