class Opal::PathReader

Constants

DEFAULT_EXTENSIONS
RELATIVE_PATH_REGEXP

Attributes

file_finder[R]

Public Class Methods

new(paths = Opal.paths, extensions = DEFAULT_EXTENSIONS) click to toggle source
# File lib/opal/path_reader.rb, line 11
def initialize(paths = Opal.paths, extensions = DEFAULT_EXTENSIONS)
  @file_finder = Hike::Trail.new
  @file_finder.append_paths(*paths)
  @file_finder.append_extensions(*extensions)
end

Public Instance Methods

append_paths(*paths) click to toggle source
# File lib/opal/path_reader.rb, line 39
def append_paths(*paths)
  file_finder.append_paths(*paths)
end
expand(path) click to toggle source
# File lib/opal/path_reader.rb, line 23
def expand(path)
  if Pathname.new(path).absolute? || path =~ RELATIVE_PATH_REGEXP
    path
  else
    find_path(path)
  end
end
extensions() click to toggle source
# File lib/opal/path_reader.rb, line 35
def extensions
  file_finder.extensions
end
paths() click to toggle source
# File lib/opal/path_reader.rb, line 31
def paths
  file_finder.paths
end
read(path) click to toggle source
# File lib/opal/path_reader.rb, line 17
def read(path)
  full_path = expand(path)
  return nil if full_path.nil?
  File.open(full_path, 'rb:UTF-8', &:read) if File.exist?(full_path)
end

Private Instance Methods

find_path(path) click to toggle source
# File lib/opal/path_reader.rb, line 45
def find_path(path)
  pathname = Pathname(path)
  return path if pathname.absolute? && pathname.exist?
  file_finder.find(path)
end