Class: Packs::Private::InteractiveCli::UseCases::MovePack

Inherits:
Object
  • Object
show all
Extended by:
T::Helpers, T::Sig
Includes:
Interface
Defined in:
lib/packs/private/interactive_cli/use_cases/move_pack.rb

Instance Method Summary collapse

Methods included from Interface

all, included

Instance Method Details

#perform!(prompt) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/packs/private/interactive_cli/use_cases/move_pack.rb', line 13

def perform!(prompt)
  move_type = prompt.select(
    'What do you want to do?',
    {
      'Move a child pack to be nested under a parent pack' => :move_to_parent,
      'Move a pack to a folder that is not a pack' =>
       :move_to_folder
    }
  )

  case move_type
  when :move_to_parent
    child_pack = PackSelector.single_pack_select(prompt, question_text: 'Please select the child pack that will be nested')
    parent_pack = PackSelector.single_pack_select(prompt, question_text: 'Please select the pack that will be the parent')

    Packs.move_to_parent!(
      parent_name: parent_pack.name,
      pack_name: child_pack.name,
      per_file_processors: [Packs::RubocopPostProcessor.new, Packs::CodeOwnershipPostProcessor.new]
    )
  when :move_to_folder
    pack = PackSelector.single_pack_select(prompt, question_text: 'Please select the pack that you want to move')
    destination = PackDirectorySelector.select(prompt, question_text: "What directory do you want to move #{pack.name} to?")

    if Packs.find(destination)
      use_move_to_parent = prompt.select(
        "The directory #{destination} contains a pack. Add #{pack.last_name} as a dependency?",
        { 'Yes' => true, 'No' => false }
      )

      if use_move_to_parent
        Packs.move_to_parent!(
          parent_name: destination,
          pack_name: pack.name,
          per_file_processors: [Packs::RubocopPostProcessor.new, Packs::CodeOwnershipPostProcessor.new]
        )

        return
      end
    end

    Packs.move_to_folder!(
      pack_name: pack.name,
      destination: destination,
      per_file_processors: [Packs::RubocopPostProcessor.new, Packs::CodeOwnershipPostProcessor.new]
    )
  end
end

#user_facing_nameObject



63
64
65
# File 'lib/packs/private/interactive_cli/use_cases/move_pack.rb', line 63

def user_facing_name
  'Move a pack'
end