Class: RestoreFromRepository::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/restore_from_repository/repository.rb

Overview

The git repository

Constant Summary collapse

REF =
'HEAD'.freeze
GIT_PATH =
'.'.freeze
GIT_OPTIONS =
{}.freeze
NEW_LINE =
"\n".freeze

Instance Method Summary collapse

Constructor Details

#initialize(git_path = GIT_PATH, git_options = GIT_OPTIONS) ⇒ Repository

Returns Repository instance.

Parameters:

  • git_path (String) (defaults to: GIT_PATH)

    git repository path

  • git_options (Hash) (defaults to: GIT_OPTIONS)

    ruby-git options



13
14
15
16
# File 'lib/restore_from_repository/repository.rb', line 13

def initialize(git_path = GIT_PATH, git_options = GIT_OPTIONS)
  @git_path = git_path
  @git_options = git_options
end

Instance Method Details

#fetch_file(file, ref = REF, new_line = NEW_LINE) ⇒ String

Returns target file contents.

Parameters:

  • file (String)

    target file

  • ref (String) (defaults to: REF)

    git ref

  • new_line (String) (defaults to: NEW_LINE)

    file’s ending new line

Returns:

  • (String)

    target file contents

Raises:

  • (TypeError)


28
29
30
31
32
33
34
# File 'lib/restore_from_repository/repository.rb', line 28

def fetch_file(file, ref = REF, new_line = NEW_LINE)
  raise TypeError if file.nil?

  # NOTE: git.cat_file trims last \n?
  text = git.cat_file("#{ref}:#{file}")
  text + new_line
end

#gitGit::Base

Returns ruby-git object.

Returns:

  • (Git::Base)

    ruby-git object



19
20
21
# File 'lib/restore_from_repository/repository.rb', line 19

def git
  @git ||= Git.open(@git_path, @git_options)
end