Class: RestoreBundledWith::Repository

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

Constant Summary collapse

LOCK_FILE =
'Gemfile.lock'
REF =
'HEAD'
GIT_PATH =
'.'
GIT_OPTIONS =
{}
NEW_LINE =
"\n"

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Repository.



9
10
11
12
# File 'lib/restore_bundled_with/repository.rb', line 9

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) ⇒ Object



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

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

#gitObject



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

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