Class: RestoreBundledWith::Repository

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

Overview

The git repository

Constant Summary collapse

LOCK_FILE =
'Gemfile.lock'.freeze
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



14
15
16
17
# File 'lib/restore_bundled_with/repository.rb', line 14

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 = LOCK_FILE, ref = REF, new_line = NEW_LINE) ⇒ String

Returns target file contents.

Parameters:

  • file (String) (defaults to: LOCK_FILE)

    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



29
30
31
32
33
# File 'lib/restore_bundled_with/repository.rb', line 29

def fetch_file(file = LOCK_FILE, ref = REF, new_line = NEW_LINE)
  # 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



20
21
22
# File 'lib/restore_bundled_with/repository.rb', line 20

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