class Ytrbium::FileResolver
Attributes
paths[R]
Public Class Methods
new(paths = nil)
click to toggle source
# File lib/ytrbium/file_resolver.rb, line 6 def initialize(paths = nil) @paths = paths && Array(paths) || [Dir.getwd] init_search end
Public Instance Methods
expand_path(name)
click to toggle source
# File lib/ytrbium/file_resolver.rb, line 20 def expand_path(name) path = @search.detect { |path| (path + name).exist? } raise ArgumentError, "No file #{name} found" unless path (path.expand_path + name).to_s end
load(name) { |file, filename| ... }
click to toggle source
# File lib/ytrbium/file_resolver.rb, line 26 def load(name) filename = expand_path name File.open(filename, "r") { |file| yield file, filename } end
paths=(new_paths)
click to toggle source
# File lib/ytrbium/file_resolver.rb, line 11 def paths=(new_paths) unless new_paths raise ArgumentError, "must provide a string path or array of string paths" end @paths = Array(new_paths) init_search end
Private Instance Methods
init_search()
click to toggle source
# File lib/ytrbium/file_resolver.rb, line 31 def init_search @search = [*@paths, *$LOAD_PATH].map { |p| Pathname.new(p) } end