class GithubToCanvasQuiz::RepositoryInterface
Interface for working with a local git repo
Attributes
git[R]
path[R]
Public Class Methods
new(path)
click to toggle source
# File lib/github_to_canvas_quiz/repository_interface.rb, line 8 def initialize(path) path = File.expand_path(path) raise DirectoryNotFoundError unless Pathname(path).directory? @path = path @git = Git.init(path) end
Public Instance Methods
commit_files(*filepaths, message)
click to toggle source
# File lib/github_to_canvas_quiz/repository_interface.rb, line 16 def commit_files(*filepaths, message) relative_paths = filepaths.map { |filepath| relative_path(filepath) } return unless new_repo? || relative_paths.any? { |filepath| pending_changes?(filepath) } git.add(relative_paths) git.commit("AUTO: #{message}") end
Private Instance Methods
new_repo?()
click to toggle source
# File lib/github_to_canvas_quiz/repository_interface.rb, line 35 def new_repo? git.log.size.zero? rescue Git::GitExecuteError => e # ruby-git raises an exception when calling git.log.size on a repo with no commits /does not have any commits yet/.match?(e.message) end
pending_changes?(filepath)
click to toggle source
# File lib/github_to_canvas_quiz/repository_interface.rb, line 31 def pending_changes?(filepath) git.status.untracked?(filepath) || git.status.changed?(filepath) || git.status.added?(filepath) end
relative_path(filepath)
click to toggle source
# File lib/github_to_canvas_quiz/repository_interface.rb, line 26 def relative_path(filepath) pathname = Pathname(filepath) pathname.relative? ? pathname.to_s : pathname.relative_path_from(path).to_s end