Class: Git::Status
- Inherits:
-
Object
- Object
- Git::Status
- Includes:
- Enumerable
- Defined in:
- lib/git/status.rb,
lib/git/status.rb,
lib/git/status.rb
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
true
ornil
. - #untracked?(file) ⇒ Boolean
Constructor Details
#initialize(base) ⇒ Status
Returns a new instance of Status.
16 17 18 19 20 |
# File 'lib/git/status.rb', line 16 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.
36 |
# File 'lib/git/status.rb', line 36 def [](file) = @files[file] |
#added
24 |
# File 'lib/git/status.rb', line 24 def added = @added ||= select_files { |f| f.type == 'A' } |
#added?(file) ⇒ Boolean
31 |
# File 'lib/git/status.rb', line 31 def added?(file) = file_in_collection?(:added, file) |
#changed
File status collections, memoized for performance.
23 |
# File 'lib/git/status.rb', line 23 def changed = @changed ||= select_files { |f| f.type == 'M' } |
#changed?(file) ⇒ Boolean
Predicate methods to check the status of a specific file.
30 |
# File 'lib/git/status.rb', line 30 def changed?(file) = file_in_collection?(:changed, file) |
#deleted
25 26 |
# File 'lib/git/status.rb', line 25 def deleted = @deleted ||= select_files { |f| f.type == 'D' } # This works with `true` or `nil` |
#deleted?(file) ⇒ Boolean
32 |
# File 'lib/git/status.rb', line 32 def deleted?(file) = file_in_collection?(:deleted, file) |
#each
37 |
# File 'lib/git/status.rb', line 37 def each(&) = @files.values.each(&) |
#pretty
Returns a formatted string representation of the status.
40 41 42 |
# File 'lib/git/status.rb', line 40 def pretty map { |file| pretty_file(file) }.join << "\n" end |
#untracked
This works with true
or nil
27 |
# File 'lib/git/status.rb', line 27 def untracked = @untracked ||= select_files(&:untracked) |
#untracked?(file) ⇒ Boolean
33 |
# File 'lib/git/status.rb', line 33 def untracked?(file) = file_in_collection?(:untracked, file) |