Class: GithubToCanvasQuiz::RepositoryInterface

Inherits:
Object
  • Object
show all
Defined in:
lib/github_to_canvas_quiz/repository_interface.rb

Overview

Interface for working with a local git repo

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ RepositoryInterface

Returns a new instance of RepositoryInterface.



8
9
10
11
12
13
14
# 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

Instance Attribute Details

#gitObject (readonly)

Returns the value of attribute git.



6
7
8
# File 'lib/github_to_canvas_quiz/repository_interface.rb', line 6

def git
  @git
end

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/github_to_canvas_quiz/repository_interface.rb', line 6

def path
  @path
end

Instance Method Details

#commit_files(*filepaths, message) ⇒ Object



16
17
18
19
20
21
22
# 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