Class: Kamaze::Project::Tools::Git::Status::Decorator

Inherits:
Object
  • Object
show all
Defined in:
lib/kamaze/project/tools/git/status/decorator.rb

Overview

Provide decoration for status

Result of to_s, SHOULD be similar to result obtained with:

git status -z | sed "s/\x0/\n/g"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status) ⇒ Decorator

Returns a new instance of Decorator.



20
21
22
# File 'lib/kamaze/project/tools/git/status/decorator.rb', line 20

def initialize(status)
  @status = status
end

Instance Attribute Details

#statusKamaze::Project::Tools::Git::Status (readonly, protected)



38
39
40
# File 'lib/kamaze/project/tools/git/status/decorator.rb', line 38

def status
  @status
end

Instance Method Details

#filesObject



24
25
26
27
28
29
# File 'lib/kamaze/project/tools/git/status/decorator.rb', line 24

def files
  files = [status.index.to_a, status.worktree.to_a].flatten.sort_by(&:to_s)

  files.reject(&:untracked?)
       .concat(files.keep_if(&:untracked?))
end

#to_sObject



31
32
33
# File 'lib/kamaze/project/tools/git/status/decorator.rb', line 31

def to_s
  files.map { |file| "#{file.status} #{file}" }.uniq.join("\n")
end