Class: Gitw::Git::Status
- Inherits:
-
Object
- Object
- Gitw::Git::Status
- Defined in:
- lib/gitw/git/status.rb
Overview
encapsulate git porcelain status output
Class Method Summary collapse
Instance Method Summary collapse
- #changed?(filename) ⇒ Boolean
-
#initialize(files) ⇒ Status
constructor
A new instance of Status.
- #untracked?(filename) ⇒ Boolean
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
20 21 22 |
# File 'lib/gitw/git/status.rb', line 20 def changed?(filename) @index_map[filename] || @workingtree_map[filename] end |
#untracked?(filename) ⇒ Boolean
24 25 26 |
# File 'lib/gitw/git/status.rb', line 24 def untracked?(filename) @untracked_map[filename] end |