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

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

Overview

Represent index status

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from Kamaze::Project::Tools::Git::Status::FilesArray

Instance Method Details

#safe?Boolean

Denote index is safe

Unsafe index shares modifications with the worktree, thus, files SHOULD NOT be naively analyzed, for example, by running a static code analysis. Running a static code analysis on unsafe index files COULD lead to inconsistent results.

Returns:

  • (Boolean)


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

def safe?
  unsafe_files.empty?
end

#safe_filesObject

Get files present in index and considered as safe

Safe files SHOULD NOT present divergent modifications between index and worktree. As seen in unsafe_files only the modified state is considered.



60
61
62
63
64
65
# File 'lib/kamaze/project/tools/git/status/index.rb', line 60

def safe_files
  unsafe = self.unsafe_files.map { |f| f.absolute_path.to_s }

  self.to_a
      .reject { |f| unsafe.include?(f.absolute_path.to_s) }
end

#unsafe?Boolean

Returns:

  • (Boolean)


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

def unsafe?
  !safe?
end

#unsafe_filesArray<File>

Get present files in intersection between index and worktree

Returns:



45
46
47
48
49
50
51
52
53
# File 'lib/kamaze/project/tools/git/status/index.rb', line 45

def unsafe_files
  c = [self, worktree].map do |a|
    a.map { |f| f.absolute_path.to_s }
  end.freeze

  self.to_a.keep_if do |f|
    (c[0] & c[1]).include?(f.absolute_path.to_s)
  end
end

#worktreeKamaze::Project::Tools::Git::Status::Worktree (protected)

Get a fresh (not frozen) copy of worktree as seen on initialization



72
73
74
75
76
# File 'lib/kamaze/project/tools/git/status/index.rb', line 72

def worktree
  memo = Array.new(memento)

  Kamaze::Project::Tools::Git::Status::Worktree.new(memo)
end