Class: Kamaze::Project::Tools::Git::Status
- 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
- #base_dir ⇒ Pathname readonly
Instance Method Summary collapse
-
#cached ⇒ Hash
protected
Get cached filepaths.
- #decorate ⇒ Decorator
-
#index ⇒ Index
Get index.
-
#initialize(status, base_dir = Dir.pwd) ⇒ Status
constructor
A new instance of Status.
-
#prepared ⇒ Hash{String => Hash{Symbol => Symbol}}
protected
Get prepared filepaths with symbols (states).
-
#refresh! ⇒ self
Empty cache.
- #to_a ⇒ Array<File>
- #to_s ⇒ String
-
#worktree ⇒ Worktree
Get worktree.
Constructor Details
#initialize(status, base_dir = Dir.pwd) ⇒ Status
Returns a new instance of Status.
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_dir ⇒ Pathname (readonly)
32 33 34 |
# File 'lib/kamaze/project/tools/git/status.rb', line 32 def base_dir @base_dir end |
Instance Method Details
#cached ⇒ Hash (protected)
Get cached filepaths
85 86 87 |
# File 'lib/kamaze/project/tools/git/status.rb', line 85 def cached (@cached ||= prepared) end |
#decorate ⇒ Decorator
43 44 45 |
# File 'lib/kamaze/project/tools/git/status.rb', line 43 def decorate Decorator.new(self) end |
#index ⇒ Index
Get index
64 65 66 |
# File 'lib/kamaze/project/tools/git/status.rb', line 64 def index Index.new(self.to_a) end |
#prepared ⇒ Hash{String => Hash{Symbol => Symbol}} (protected)
Get prepared filepaths with symbols (states)
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
55 56 57 58 59 |
# File 'lib/kamaze/project/tools/git/status.rb', line 55 def refresh! @cached = nil self end |
#to_a ⇒ Array<File>
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_s ⇒ String
48 49 50 |
# File 'lib/kamaze/project/tools/git/status.rb', line 48 def to_s decorate.to_s end |