Class: Opal::PathReader

Inherits:
Object
  • Object
show all
Defined in:
opal/lib/opal/path_reader.rb

Instance Method Summary collapse

Constructor Details

#initialize(file_finder = HikePathFinder.new) ⇒ PathReader

Returns a new instance of PathReader


5
6
7
# File 'opal/lib/opal/path_reader.rb', line 5

def initialize(file_finder = HikePathFinder.new)
  @file_finder = file_finder
end

Instance Method Details

#append_paths(*paths) ⇒ Object


27
28
29
# File 'opal/lib/opal/path_reader.rb', line 27

def append_paths(*paths)
  file_finder.append_paths(*paths)
end

#expand(path) ⇒ Object


15
16
17
18
19
20
21
# File 'opal/lib/opal/path_reader.rb', line 15

def expand(path)
  if Pathname.new(path).absolute? || path =~ %r{\A\.?\.#{File::SEPARATOR}}
    path
  else
    file_finder.find(path)
  end
end

#pathsObject


23
24
25
# File 'opal/lib/opal/path_reader.rb', line 23

def paths
  file_finder.paths
end

#read(path) ⇒ Object


9
10
11
12
13
# File 'opal/lib/opal/path_reader.rb', line 9

def read(path)
  full_path = expand(path)
  return nil if full_path.nil?
  File.open(full_path, 'rb:UTF-8'){|f| f.read}
end