Class: Kamaze::Project::Tools::Git::Status

Inherits:
Object
  • Object
show all
Defined in:
lib/kamaze/project/tools/git/status.rb,
lib/kamaze/project/tools/git.rb,
lib/kamaze/project/tools/git/status/index.rb,
lib/kamaze/project/tools/git/status/worktree.rb

Overview

rubocop:disable Style/Documentation

Defined Under Namespace

Classes: Decorator, File, FilesArray, Index, Worktree

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status, base_dir = Dir.pwd) ⇒ Status

Returns a new instance of Status.

Parameters:

  • status (Hash{String => Array<Symbol>})
  • base_dir (String) (defaults to: Dir.pwd)


30
31
32
33
34
# File 'lib/kamaze/project/tools/git/status.rb', line 30

def initialize(status, base_dir = Dir.pwd)
  @base_dir = ::Pathname.new(base_dir)
  @status = status.clone
  @cached = nil
end

Instance Attribute Details

#base_dirPathname (readonly)

Returns:

  • (Pathname)


26
27
28
# File 'lib/kamaze/project/tools/git/status.rb', line 26

def base_dir
  @base_dir
end

Instance Method Details

#cachedHash (protected)

Get cached filepaths

Returns:

  • (Hash)


79
80
81
82
83
# File 'lib/kamaze/project/tools/git/status.rb', line 79

def cached
  @cached ||= prepared

  @cached
end

#decorateDecorator

Returns:



37
38
39
# File 'lib/kamaze/project/tools/git/status.rb', line 37

def decorate
  Decorator.new(self)
end

#indexIndex

Get index

Returns:



58
59
60
# File 'lib/kamaze/project/tools/git/status.rb', line 58

def index
  Index.new(self.to_a)
end

#preparedHash{String => Hash{Symbol => Symbol}} (protected)

Get prepared filepaths with symbols (states)

Returns:

  • (Hash{String => Hash{Symbol => Symbol}})


88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/kamaze/project/tools/git/status.rb', line 88

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

#refresh!self

Empty cache

Returns:

  • (self)


49
50
51
52
53
# File 'lib/kamaze/project/tools/git/status.rb', line 49

def refresh!
  @cached = nil

  self
end

#to_aArray<File>

Returns:



70
71
72
# File 'lib/kamaze/project/tools/git/status.rb', line 70

def to_a
  cached.to_a.map { |v| File.new(v.fetch(0), v.fetch(1), base_dir) }
end

#to_sString

Returns:

  • (String)


42
43
44
# File 'lib/kamaze/project/tools/git/status.rb', line 42

def to_s
  decorate.to_s
end

#worktreeWorktree

Get worktree

Returns:



65
66
67
# File 'lib/kamaze/project/tools/git/status.rb', line 65

def worktree
  Worktree.new(self.to_a)
end