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/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)


36
37
38
39
40
# 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

Instance Attribute Details

#base_dirPathname (readonly)

Returns:

  • (Pathname)


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

def base_dir
  @base_dir
end

Instance Method Details

#cachedHash (protected)

Get cached filepaths

Returns:

  • (Hash)


85
86
87
# File 'lib/kamaze/project/tools/git/status.rb', line 85

def cached
  (@cached ||= prepared)
end

#decorateDecorator

Returns:



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

def decorate
  Decorator.new(self)
end

#indexIndex

Get index

Returns:



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

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}})


92
93
94
95
96
97
98
99
100
101
102
103
104
# 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

#refresh!self

Empty cache

Returns:

  • (self)


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

def refresh!
  @cached = nil

  self
end

#to_aArray<File>

Returns:



76
77
78
# 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_sString

Returns:

  • (String)


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

def to_s
  decorate.to_s
end

#worktreeWorktree

Get worktree

Returns:



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

def worktree
  Worktree.new(self.to_a)
end