Class: Gurney::GitFileReader

Inherits:
Object
  • Object
show all
Defined in:
lib/gurney/git_file_reader.rb

Instance Method Summary collapse

Constructor Details

#initialize(git, branch, read_from_git:, prefix: '.') ⇒ GitFileReader

Returns a new instance of GitFileReader.



4
5
6
7
8
9
# File 'lib/gurney/git_file_reader.rb', line 4

def initialize(git, branch, read_from_git:, prefix: '.')
  @git = git
  @branch = branch
  @read_from_git = read_from_git
  @prefix = prefix
end

Instance Method Details

#read(filename) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/gurney/git_file_reader.rb', line 11

def read(filename)
  prefixed_filename = File.join(@prefix, filename)
  if @read_from_git
    begin
      @git.show("#{@branch}:#{prefixed_filename}")
    rescue Git::GitExecuteError
      # happens if branch does not exist
    end
  else
    File.read(prefixed_filename) if File.exist?(prefixed_filename)
  end
end