Class: Git::Status
Overview
The Status class gets the status of a git repository. It identifies which files have been modified, added, or deleted, including untracked files. The Status object is an Enumerable of StatusFile objects.
Defined Under Namespace
Classes: StatusFile, StatusFileFactory
Instance Method Summary collapse
-
#[](file)
Access a status file by path, or iterate over all status files.
- #added
- #added?(file) ⇒ Boolean
-
#changed
File status collections, memoized for performance.
-
#changed?(file) ⇒ Boolean
Predicate methods to check the status of a specific file.
- #deleted
- #deleted?(file) ⇒ Boolean
- #each
-
#initialize(base) ⇒ Status
constructor
A new instance of Status.
-
#pretty
Returns a formatted string representation of the status.
-
#untracked
This works with
trueornil. - #untracked?(file) ⇒ Boolean
Constructor Details
#initialize(base) ⇒ Status
Returns a new instance of Status.
14 15 16 17 18 |
# File 'lib/git/status.rb', line 14 def initialize(base) @base = base # The factory returns a hash of file paths to StatusFile objects. @files = StatusFileFactory.new(base).construct_files end |
Instance Method Details
#[](file)
Access a status file by path, or iterate over all status files.
34 |
# File 'lib/git/status.rb', line 34 def [](file) = @files[file] |
#added
22 |
# File 'lib/git/status.rb', line 22 def added = @added ||= select_files { |f| f.type == 'A' } |
#added?(file) ⇒ Boolean
29 |
# File 'lib/git/status.rb', line 29 def added?(file) = file_in_collection?(:added, file) |
#changed
File status collections, memoized for performance.
21 |
# File 'lib/git/status.rb', line 21 def changed = @changed ||= select_files { |f| f.type == 'M' } |
#changed?(file) ⇒ Boolean
Predicate methods to check the status of a specific file.
28 |
# File 'lib/git/status.rb', line 28 def changed?(file) = file_in_collection?(:changed, file) |
#deleted
23 24 |
# File 'lib/git/status.rb', line 23 def deleted = @deleted ||= select_files { |f| f.type == 'D' } # This works with `true` or `nil` |
#deleted?(file) ⇒ Boolean
30 |
# File 'lib/git/status.rb', line 30 def deleted?(file) = file_in_collection?(:deleted, file) |
#each
35 |
# File 'lib/git/status.rb', line 35 def each(&) = @files.values.each(&) |
#pretty
Returns a formatted string representation of the status.
38 39 40 |
# File 'lib/git/status.rb', line 38 def pretty map { |file| pretty_file(file) }.join << "\n" end |
#untracked
This works with true or nil
25 |
# File 'lib/git/status.rb', line 25 def untracked = @untracked ||= select_files(&:untracked) |
#untracked?(file) ⇒ Boolean
31 |
# File 'lib/git/status.rb', line 31 def untracked?(file) = file_in_collection?(:untracked, file) |