class Git::Status::Git::Status::StatusFileFactory

A factory class responsible for fetching git status data and building a hash of StatusFile objects. @api private

Public Class Methods

new(base) click to toggle source
# File lib/git/status.rb, line 121
def initialize(base)
  @base = base
  @lib = base.lib
end

Public Instance Methods

construct_files() click to toggle source

Gathers all status data and builds a hash of file paths to StatusFile objects.

# File lib/git/status.rb, line 128
def construct_files
  files_data = fetch_all_files_data
  files_data.transform_values do |data|
    StatusFile.new(@base, data)
  end
end

Private Instance Methods

fetch_all_files_data() click to toggle source

Fetches and merges status information from multiple git commands.

# File lib/git/status.rb, line 138
def fetch_all_files_data
  files = @lib.ls_files # Start with files tracked in the index.
  merge_untracked_files(files)
  merge_modified_files(files)
  merge_head_diffs(files)
  files
end
merge_head_diffs(files) click to toggle source
# File lib/git/status.rb, line 159
def merge_head_diffs(files)
  return if @lib.empty?

  # Merge changes between HEAD and the index.
  @lib.diff_index('HEAD').each do |path, data|
    (files[path] ||= {}).merge!(data)
  end
end
merge_modified_files(files) click to toggle source
# File lib/git/status.rb, line 152
def merge_modified_files(files)
  # Merge changes between the index and the working directory.
  @lib.diff_files.each do |path, data|
    (files[path] ||= {}).merge!(data)
  end
end
merge_untracked_files(files) click to toggle source
# File lib/git/status.rb, line 146
def merge_untracked_files(files)
  @lib.untracked_files.each do |file|
    files[file] = { path: file, untracked: true }
  end
end