Module: Pruner::Branches

Extended by:
MessageFormatter
Defined in:
lib/pruner/branches.rb

Class Method Summary collapse

Methods included from MessageFormatter

abort_message, body_message, title_message

Class Method Details

.branchesarray

All branches

Returns:

  • (array)

    all branches



29
30
31
# File 'lib/pruner/branches.rb', line 29

def branches
  git.branches.local.to_a
end

.canceled_messagestring

Canceled message

Returns:

  • (string)

    message indicating the operation was canceled



91
92
93
# File 'lib/pruner/branches.rb', line 91

def canceled_message
  abort_message("Operation canceled by user.")
end

.confirmation_messagestring

Confirmation message that the branches were removed

Returns:

  • (string)

    Branches deleted message



73
74
75
# File 'lib/pruner/branches.rb', line 73

def confirmation_message
  title_message("Branches Deleted")
end

.confirmation_promptboolean

Prompt to confirm deletion of branches

Returns:

  • (boolean)

    T:F depending on selection



63
64
65
66
# File 'lib/pruner/branches.rb', line 63

def confirmation_prompt
  title_message("Are you sure you want to delete these branches?")
  prompt.yes?("")
end

.confirmed_selectionsarray

Selected branches for deletion

Returns:

  • (array)

    array of branch names



52
53
54
55
56
# File 'lib/pruner/branches.rb', line 52

def confirmed_selections
  selections = prompt.multi_select(title_message("Select branches to delete"), branches)
  no_selections if selections.empty?
  confirmation_prompt ? selections : canceled_message
end

.delete(selections) ⇒ string

Loop to delete the selected branches

Returns:

  • (string)

    confirmation_message



38
39
40
41
42
43
44
45
# File 'lib/pruner/branches.rb', line 38

def delete(selections)
  title_message("Deleting Branches")
  selections.each do |s|
    s.delete
    puts "- #{s}"
  end
  confirmation_message
end

.gitobject

Initialize new Git object

Returns:

  • (object)

    Git



20
21
22
# File 'lib/pruner/branches.rb', line 20

def git
  @git ||= Git.open(`pwd`.strip)
end

.no_selectionsstring

No selection message

Returns:

  • (string)

    message indicating no selections were made



82
83
84
# File 'lib/pruner/branches.rb', line 82

def no_selections
  abort_message("No selections were made.")
end

.promptobject

Initialize new TTY Prompt

Returns:

  • (object)

    TTY::Prompt



11
12
13
# File 'lib/pruner/branches.rb', line 11

def prompt
  @prompt ||= TTY::Prompt.new
end