Module | Fileable::DSL |
In: |
lib/more/facets/fileable.rb
|
Find file. The path has to be either the exact path or the directory where a standard-named file resides.
# File lib/more/facets/fileable.rb, line 140 def file(path=nil) if !path raise LoadError unless filename path = filename elsif File.directory?(path) raise LoadError unless filename path = File.join(path, filename) end if file = Dir.glob(path, File::FNM_CASEFOLD)[0] File.expand_path(file) else raise Errno::ENOENT end end
An initializer that can take either a File, Pathname or raw data. This works much like YAML::load does. Unlike open, load requires an exact path parameter.
# File lib/more/facets/fileable.rb, line 103 def load(path_or_data) case path_or_data when File open(path_or_data.path) when Pathname open(path_or_data.realpath) else new(path_or_data) end end
Locate file (case insensitive).
# File lib/more/facets/fileable.rb, line 123 def locate(name=nil) name ||= filename raise LoadError unless name Dir.ascend(Dir.pwd) do |dir| match = File.join(dir, name) files = Dir.glob(match, File::FNM_CASEFOLD) if file = files[0] return file end end return nil end