Class: Git::Status

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(base) ⇒ Status

Returns a new instance of Status.

Parameters:



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

Returns:

  • (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.

Returns:

  • (Boolean)


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

Returns:

  • (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

Returns:

  • (Boolean)


33
# File 'lib/git/status.rb', line 33

def untracked?(file) = file_in_collection?(:untracked, file)