Class: Ytrbium::FileResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/ytrbium/file_resolver.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(paths = nil) ⇒ FileResolver

Returns a new instance of FileResolver.



6
7
8
9
# File 'lib/ytrbium/file_resolver.rb', line 6

def initialize(paths = nil)
  @paths = paths && Array(paths) || [Dir.getwd]
  init_search
end

Instance Attribute Details

#pathsObject

Returns the value of attribute paths.



4
5
6
# File 'lib/ytrbium/file_resolver.rb', line 4

def paths
  @paths
end

Instance Method Details

#expand_path(name) ⇒ Object

Raises:

  • (ArgumentError)


20
21
22
23
24
# 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) ⇒ Object



26
27
28
29
# File 'lib/ytrbium/file_resolver.rb', line 26

def load(name)
  filename = expand_path name
  File.open(filename, "r") { |file| yield file, filename }
end