class GitAccess

Constants

DELETED
GIT_DIR
MODES

Attributes

flag[RW]
id[RW]
repo[RW]

Public Instance Methods

changed_files() click to toggle source
# File lib/ducalis/git_access.rb, line 26
def changed_files
  changes.map(&:path)
end
for(path) click to toggle source
# File lib/ducalis/git_access.rb, line 30
def for(path)
  return find(path) unless path.include?(Dir.pwd)

  find(Pathname.new(path).relative_path_from(Pathname.new(Dir.pwd)).to_s)
end
store_pull_request!(info) click to toggle source
# File lib/ducalis/git_access.rb, line 20
def store_pull_request!(info)
  repo, id = info
  self.repo = repo
  self.id = id
end

Private Instance Methods

changes() click to toggle source
# File lib/ducalis/git_access.rb, line 42
def changes
  return default_value if flag.nil? || !under_git?

  @changes ||= patch_diffs
end
default_value() click to toggle source
# File lib/ducalis/git_access.rb, line 56
def default_value
  raise Ducalis::MissingGit unless flag.nil?

  []
end
find(path) click to toggle source
# File lib/ducalis/git_access.rb, line 62
def find(path)
  changes.find { |diff| diff.path == path } || NilDiff.new(nil, path)
end
patch_diffs() click to toggle source
# File lib/ducalis/git_access.rb, line 48
def patch_diffs
  MODES.fetch(flag)
       .call(Git.open(Dir.pwd))
       .reject { |diff| diff.type == DELETED }
       .select { |diff| File.exist?(diff.path) }
       .map    { |diff| GitDiff.new(diff, diff.path) }
end
under_git?() click to toggle source
# File lib/ducalis/git_access.rb, line 38
def under_git?
  @under_git ||= Dir.exist?(File.join(Dir.pwd, GIT_DIR))
end