Methods
Public Instance methods
Find file. The path has to be either the exact path or the directory where a standard-named file resides.
[ show source ]
# File lib/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
Override this with the name or name-glob of the default file. If no default, return nil.
[ show source ]
# File lib/facets/fileable.rb, line 86 def filename; nil; end
While this doesn‘t allpy to classes, for modules it is needed to keep the DSL inheritance going.
[ show source ]
# File lib/facets/fileable.rb, line 79 def included(base) base.extend DSL 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.
[ show source ]
# File lib/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
Load cache. PackageInfo is multiton when loaded by file.
[ show source ]
# File lib/facets/fileable.rb, line 157 def load_cache @load_cache ||= {} end
Locate file (case insensitive).
[ show source ]
# File lib/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
Lookup file.
[ show source ]
# File lib/facets/fileable.rb, line 116 def lookup(name=nil) file = locate(name) file ? open(file) : nil #raise LoadError end
Load from file(s).
[ show source ]
# File lib/facets/fileable.rb, line 90 def open(path=nil) file = file(path) if file fobj = new fobj.send(:read, file) return fobj end end