Class: DevContext::Status

Inherits:
Object
  • Object
show all
Defined in:
lib/dev_context/status.rb

Instance Method Summary collapse

Constructor Details

#initialize(repo_path:) ⇒ Status

Returns a new instance of Status.



5
6
7
# File 'lib/dev_context/status.rb', line 5

def initialize(repo_path:)
  @repo_path = repo_path
end

Instance Method Details

#countsObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/dev_context/status.rb', line 9

def counts
  lines = porcelain_lines
  result = { m: 0, u: 0, n: 0, d: 0, r: 0 }

  lines.each do |line|
    x = line[0]
    y = line[1]

    if line.start_with?("??")
      result[:n] += 1
      next
    end

    result[:m] += 1 if x == "M"
    result[:u] += 1 if y == "M"
    result[:n] += 1 if x == "A"
    result[:d] += 1 if x == "D" || y == "D"
    result[:r] += 1 if x == "R" || y == "R"
  end

  result
end

#one_lineObject



32
33
34
35
36
37
# File 'lib/dev_context/status.rb', line 32

def one_line
  c = counts
  return "Up to date" if c.values.all?(&:zero?)

  "m:#{c[:m]} u:#{c[:u]} n:#{c[:n]} d:#{c[:d]} r:#{c[:r]}"
end