Class: Augit::Inspector

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::DateHelper, ActionView::Helpers::TextHelper
Defined in:
lib/augit/inspector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Inspector

Returns a new instance of Inspector.



11
12
13
14
15
16
17
18
# File 'lib/augit/inspector.rb', line 11

def initialize(options = {})
  @repo = Augit::Repo.new(options)
  @origin = repo.origin
  @branches = repo.branch_names
  @merged = repo.merged_branches
  @unmerged = branches - merged
  @regexp   = options[:regexp]
end

Instance Attribute Details

#branchesObject (readonly)

Returns the value of attribute branches.



9
10
11
# File 'lib/augit/inspector.rb', line 9

def branches
  @branches
end

#mergedObject (readonly)

Returns the value of attribute merged.



9
10
11
# File 'lib/augit/inspector.rb', line 9

def merged
  @merged
end

#originObject (readonly)

Returns the value of attribute origin.



9
10
11
# File 'lib/augit/inspector.rb', line 9

def origin
  @origin
end

#repoObject (readonly)

Returns the value of attribute repo.



9
10
11
# File 'lib/augit/inspector.rb', line 9

def repo
  @repo
end

#termObject (readonly)

Returns the value of attribute term.



9
10
11
# File 'lib/augit/inspector.rb', line 9

def term
  @term
end

#unmergedObject (readonly)

Returns the value of attribute unmerged.



9
10
11
# File 'lib/augit/inspector.rb', line 9

def unmerged
  @unmerged
end

Instance Method Details

#delete(name) ⇒ Object



81
82
83
84
85
86
# File 'lib/augit/inspector.rb', line 81

def delete(name)
  print '!'.red
  puts " Deleting: #{name}"
  `git push origin :#{name}`
  puts "Success!".green
end

#listObject



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

def list
  print "Searching remote branches:"

  if merged.any?
    merged_actions
  else
    puts "\n> All remote branches that are merged have been deleted".green
  end

  if unmerged.any?
    print_key
    unmerged_actions
  else
    puts "\n> All unmerged remote branches have been deleted".green
  end
end

#merged_actionsObject



58
59
60
61
62
63
64
65
66
67
# File 'lib/augit/inspector.rb', line 58

def merged_actions
  puts "#{pluralize(merged.length, 'branch')} merged into master:".green
  puts "  #{merged.join("\n  ")}"

  case prompt("Delete #{pluralize(merged.length, 'branch')}?")
  when :y; merged.each{|branch| delete(branch) }
  when :n;
  when :q; exit
  end
end

#presenter(branch, origin) ⇒ Object



88
89
90
# File 'lib/augit/inspector.rb', line 88

def presenter(branch, origin)
  Augit::Presenter.new(branch, origin)
end

#prompt(message) ⇒ Object



53
54
55
56
# File 'lib/augit/inspector.rb', line 53

def prompt(message)
  choice = ask("#{message} |(y)es, (N)o, (q)uit|".cyan)
  choice.strip.downcase.to_sym
end

#section_message(type, data, filter) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/augit/inspector.rb', line 37

def section_message(type, data, filter)
  filter = @regexp ? "matching /#{@regexp}/ " : ''
  branches = pluralize(data.length, 'branch')
  body = "#{type} into master"
  message = "#{branches} #{filter}#{body}"
  data.any? ? "#{message}:" : message
end

#statusObject



45
46
47
48
49
50
51
# File 'lib/augit/inspector.rb', line 45

def status
  puts section_message('merged', merged, @regexp).green
  puts "  #{merged.join("\n  ")}"

  puts section_message('not merged', unmerged, @regexp).red
  puts "  #{unmerged.join("\n  ")}"
end

#unmerged_actionsObject



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/augit/inspector.rb', line 69

def unmerged_actions
  unmerged.each do |branch|
    presenter(branch, origin).print

    case prompt("Delete #{branch}?")
    when :y; delete(branch)
    when :n;
    when :q; exit
    end
  end
end