Class: Ytrbium::FileResolver
Instance Attribute Summary collapse
-
#paths ⇒ Object
Returns the value of attribute paths.
Instance Method Summary collapse
- #expand_path(name) ⇒ Object
-
#initialize(paths = nil) ⇒ FileResolver
constructor
A new instance of FileResolver.
- #load(name) ⇒ Object
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
#paths ⇒ Object
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
20 21 22 23 24 |
# File 'lib/ytrbium/file_resolver.rb', line 20 def (name) path = @search.detect { |path| (path + name).exist? } raise ArgumentError, "No file #{name} found" unless path (path. + name).to_s end |
#load(name) ⇒ Object
26 27 28 29 |
# File 'lib/ytrbium/file_resolver.rb', line 26 def load(name) filename = name File.open(filename, "r") { |file| yield file, filename } end |