Class: GemInstaller::FileReader

Inherits:
Object
  • Object
show all
Defined in:
lib/geminstaller/file_reader.rb

Instance Method Summary collapse

Instance Method Details

#do_open(file_path) ⇒ Object



23
24
25
# File 'lib/geminstaller/file_reader.rb', line 23

def do_open(file_path)
  File.open(file_path)
end

#do_read(file) ⇒ Object



27
28
29
# File 'lib/geminstaller/file_reader.rb', line 27

def do_read(file)
  file.read
end

#read(file_path) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/geminstaller/file_reader.rb', line 3

def read(file_path)
  file_contents = nil
  if !File.exist?(file_path) then
    raise GemInstaller::MissingFileError.new("#{file_path}")
  end

  file = nil
  begin
    file = do_open(file_path)
  rescue
    raise GemInstaller::GemInstallerError.new("Error: Unable open file #{file_path}.  Please ensure that this file can be opened.\n")
  end

  begin
    do_read(file)
  rescue
    raise GemInstaller::GemInstallerError.new("Error: Unable read file #{file_path}.  Please ensure that this file can be read.\n")
  end
end