Class: Kamaze::Project::Tools::Git::Status
- 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
- #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.
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_dir ⇒ Pathname (readonly)
26 27 28 |
# File 'lib/kamaze/project/tools/git/status.rb', line 26 def base_dir @base_dir end |
Instance Method Details
#cached ⇒ Hash (protected)
Get cached filepaths
79 80 81 82 83 |
# File 'lib/kamaze/project/tools/git/status.rb', line 79 def cached @cached ||= prepared @cached end |
#decorate ⇒ Decorator
37 38 39 |
# File 'lib/kamaze/project/tools/git/status.rb', line 37 def decorate Decorator.new(self) end |
#index ⇒ Index
Get index
58 59 60 |
# File 'lib/kamaze/project/tools/git/status.rb', line 58 def index Index.new(self.to_a) end |
#prepared ⇒ Hash{String => Hash{Symbol => Symbol}} (protected)
Get prepared filepaths with symbols (states)
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
49 50 51 52 53 |
# File 'lib/kamaze/project/tools/git/status.rb', line 49 def refresh! @cached = nil self end |
#to_a ⇒ Array<File>
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_s ⇒ String
42 43 44 |
# File 'lib/kamaze/project/tools/git/status.rb', line 42 def to_s decorate.to_s end |