class GitHooks::Repository::DiffIndexEntry

Constants

DIFF_STRUCTURE_REGEXP

Public Class Methods

from_file_path(repo, path, tracked = false) click to toggle source
# File lib/githooks/repository/diff_index_entry.rb, line 19
def self.from_file_path(repo, path, tracked = false)
  relative_path = Pathname.new(path)
  full_path = repo.path + relative_path
  entry_line = format(":%06o %06o %040x %040x %s\t%s",
                      0, full_path.stat.mode, 0, 0, (tracked ? '^' : '?'), relative_path.to_s)
  new(repo, entry_line)
end
new(repo, entry) click to toggle source
Calls superclass method
# File lib/githooks/repository/diff_index_entry.rb, line 27
def initialize(repo, entry)
  @repo = repo
  unless entry =~ DIFF_STRUCTURE_REGEXP
    fail ArgumentError, "Unable to parse incoming diff entry data: #{entry}"
  end
  super parse_data(entry)
end

Public Instance Methods

parse_data(entry) click to toggle source

rubocop:disable MultilineOperationIndentation

# File lib/githooks/repository/diff_index_entry.rb, line 36
def parse_data(entry) # rubocop:disable MethodLength, AbcSize
  data = Hash[
    DIFF_STRUCTURE_REGEXP.names.collect(&:to_sym).zip(
      entry.match(DIFF_STRUCTURE_REGEXP).captures
    )
  ]

  {
    from:  FileState.new(
      data[:original_mode].to_i(8),
      data[:original_sha],
      data[:file_path].nil? ? nil : Pathname.new(data[:file_path])
    ),
    to:    FileState.new(
      data[:new_mode].to_i(8),
      data[:new_sha],
      data[:rename_path].nil? ? nil : Pathname.new(data[:rename_path])
    ),
    type:  Repository::CHANGE_TYPES[data[:change_type]],
    score: data[:score].to_i
  }
end
to_repo_file() click to toggle source

rubocop:enable MultilineOperationIndentation

# File lib/githooks/repository/diff_index_entry.rb, line 60
def to_repo_file
  Repository::File.new(@repo, self)
end