class Kamaze::Project::Tools::Git::Status::File
Status file
Describe a file as seen in status, file is described by path and flags, and is immutable by design.
@see www.rubydoc.info/github/libgit2/rugged/Rugged%2FRepository%3Astatus
Attributes
@return [Pathname]
@return [String]
@return [Pathname]
Public Class Methods
@param [Pathname|String] path @param [Hash] flags @param [Pathname|String] base_dir
# File lib/kamaze/project/tools/git/status/file.rb, line 31 def initialize(path, flags, base_dir = Dir.pwd) @base_dir = ::Pathname.new(base_dir).freeze @path = ::Pathname.new(path).freeze @flags = flags.freeze end
Public Instance Methods
@return [Boolean]
# File lib/kamaze/project/tools/git/status/file.rb, line 63 def ==(other) return false unless comparable_with?(other) [[self.path.to_s, other.path.to_s], [self.base_dir.to_s, other.base_dir.to_s], [self.flags.sort, other.flags.sort]].each do |c| return false unless c[0] == c[1] end true end
Get absolute path
@return [Pathname]
# File lib/kamaze/project/tools/git/status/file.rb, line 87 def absolute_path base_dir.join(path) end
Denote instance is comparable with another object
@param [Object] other @return [Boolean]
# File lib/kamaze/project/tools/git/status/file.rb, line 79 def comparable_to?(other) [:flags, :path, :base_dir] .map { |m| other.respond_to?(m) }.uniq == [true] end
Denote deleted
@return [Boolean]
# File lib/kamaze/project/tools/git/status/file.rb, line 129 def deleted? flags.values.include?(:deleted) end
Denote ignored
@return [Boolean]
# File lib/kamaze/project/tools/git/status/file.rb, line 94 def ignored? flags.keys.include?(:ignored) end
Denote index
@return [Boolean]
# File lib/kamaze/project/tools/git/status/file.rb, line 108 def index? flags.keys.include?(:index) end
Denote deleted in index
@return [Boolean]
# File lib/kamaze/project/tools/git/status/file.rb, line 157 def index_deleted? index? and deleted? end
Denote modified in index
@return [Boolean]
# File lib/kamaze/project/tools/git/status/file.rb, line 150 def index_modified? index? and modified? end
Denote new in index
@return [Boolean]
# File lib/kamaze/project/tools/git/status/file.rb, line 143 def index_new? index? and new? end
Denote modified
@return [Boolean]
# File lib/kamaze/project/tools/git/status/file.rb, line 122 def modified? flags.values.include?(:modified) end
Denote new
@return [Boolean]
# File lib/kamaze/project/tools/git/status/file.rb, line 115 def new? flags.values.include?(:new) end
Get a status string, composed of two chars
@see git-scm.com/docs/git-status @return [String]
# File lib/kamaze/project/tools/git/status/file.rb, line 46 def status return '??' if untracked? states = [' ', ' '] mapping = { new: 'A', modified: 'M', deleted: 'D' } { index: 0, worktree: 1 }.each do |from, index| next unless self.public_send("#{from}?") mapping.each do |flag, s| states[index] = s if self.public_send("#{from}_#{flag}?") end end states.join end
@return [String]
# File lib/kamaze/project/tools/git/status/file.rb, line 38 def to_s path.to_s end
Denote untracked
@return [Boolean]
# File lib/kamaze/project/tools/git/status/file.rb, line 136 def untracked? worktree? and new? and !index? end
Denote worktree
@return [Boolean]
# File lib/kamaze/project/tools/git/status/file.rb, line 101 def worktree? flags.keys.include?(:worktree) end
Denote deleted in worktree
@return [Boolean]
# File lib/kamaze/project/tools/git/status/file.rb, line 178 def worktree_deleted? worktree? and deleted? end
Denote modified in worktree
@return [Boolean]
# File lib/kamaze/project/tools/git/status/file.rb, line 171 def worktree_modified? worktree? and modified? end
Denote new in worktree
@return [Boolean]
# File lib/kamaze/project/tools/git/status/file.rb, line 164 def worktree_new? worktree? and new? end