Class: Codeowners::Cli::Wizards::NewFileWizard

Inherits:
Object
  • Object
show all
Includes:
InteractiveOps
Defined in:
lib/codeowners/cli/wizards/new_file_wizard.rb

Overview

Suggests to add new files to the codeowners list. Only returns decision without applying any modifications.

Instance Method Summary collapse

Methods included from InteractiveOps

#ask, #yes?

Constructor Details

#initialize(default_owner) ⇒ NewFileWizard

Returns a new instance of NewFileWizard.



13
14
15
# File 'lib/codeowners/cli/wizards/new_file_wizard.rb', line 13

def initialize(default_owner)
  @default_owner = default_owner
end

Instance Method Details

#select_operation(pattern, main_group) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/codeowners/cli/wizards/new_file_wizard.rb', line 25

def select_operation(pattern, main_group)
  subgroups = main_group.subgroups_owned_by(pattern.owner)
  if subgroups.any? && (subgroup = prompt_subgroup(subgroups))
    [:insert_into_subgroup, subgroup]
  elsif yes?('Add to the end of the CODEOWNERS file?')
    :add_to_main_group
  else
    :ignore
  end
end

#suggest_adding(file, main_group) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/codeowners/cli/wizards/new_file_wizard.rb', line 17

def suggest_adding(file, main_group)
  case prompt(file)
  when 'y' then [:add, create_pattern(file, main_group)]
  when 'i' then :ignore
  when 'q' then :quit
  end
end