class Kamaze::Project::Tools::Git::Status

Provide status

Status can provide different kind of file lists, as seen by “libgit“.

“index“ and “worktree“ are directly provided throuh “status“, but files can also been easily discriminated by status.

@see Kamaze::Project::Tools::Git::Status::File

rubocop:disable Style/Documentation

Attributes

base_dir[R]

@return [Pathname]

Public Class Methods

new(status, base_dir = Dir.pwd) click to toggle source

@param [Hash{String => Array<Symbol>}] status @param [String] base_dir

# File lib/kamaze/project/tools/git/status.rb, line 36
def initialize(status, base_dir = Dir.pwd)
  @base_dir = ::Pathname.new(base_dir)
  @status = status.clone
  @cached = nil
end

Public Instance Methods

decorate() click to toggle source

@return [Decorator]

# File lib/kamaze/project/tools/git/status.rb, line 43
def decorate
  Decorator.new(self)
end
index() click to toggle source

Get index

@return [Index]

# File lib/kamaze/project/tools/git/status.rb, line 64
def index
  Index.new(self.to_a)
end
refresh!() click to toggle source

Empty cache

@return [self]

# File lib/kamaze/project/tools/git/status.rb, line 55
def refresh!
  @cached = nil

  self
end
to_a() click to toggle source

@return [Array<File>]

# File lib/kamaze/project/tools/git/status.rb, line 76
def to_a
  cached.to_a.map { |v| File.new(v.fetch(0), v.fetch(1), base_dir) }
end
to_s() click to toggle source

@return [String]

# File lib/kamaze/project/tools/git/status.rb, line 48
def to_s
  decorate.to_s
end
worktree() click to toggle source

Get worktree

@return [Worktree]

# File lib/kamaze/project/tools/git/status.rb, line 71
def worktree
  Worktree.new(self.to_a)
end

Protected Instance Methods

cached() click to toggle source

Get cached filepaths

@return [Hash]

# File lib/kamaze/project/tools/git/status.rb, line 85
def cached
  (@cached ||= prepared)
end
prepared() click to toggle source

Get prepared filepaths with symbols (states)

@return [Hash{String => Hash{Symbol => Symbol}}]

# File lib/kamaze/project/tools/git/status.rb, line 92
def prepared
  output = {}
  @status.each do |file, status_data|
    status_data.each do |status|
      status = status.to_s.split('_').map(&:to_sym)
      flags = { status[0] => status[1] || status[0] }

      output[file] = (output[file] || {}).merge(flags)
    end
  end

  output
end