Class: Gitw::Git::Status

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

Overview

encapsulate git porcelain status output

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(files) ⇒ Status

Returns a new instance of Status.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/gitw/git/status.rb', line 7

def initialize(files)
  @files = files.compact

  @index_map = {}
  @workingtree_map = {}
  @untracked_map = {}
  @files.each do |file|
    @index_map[file.path] = file if file.index_changed?
    @workingtree_map[file.path] = file if file.workingtree_changed?
    @untracked_map[file.path] = file if file.untracked?
  end
end

Class Method Details

.parse(output) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/gitw/git/status.rb', line 28

def self.parse(output)
  return new unless output

  files = output.each_line.with_object([]) do |entry, files_store|
    files_store << StatusFile.parse(entry)
  end
  new(files)
end

Instance Method Details

#changed?(filename) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/gitw/git/status.rb', line 20

def changed?(filename)
  @index_map[filename] || @workingtree_map[filename]
end

#untracked?(filename) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/gitw/git/status.rb', line 24

def untracked?(filename)
  @untracked_map[filename]
end