| 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
140: def file(path=nil)
141: if !path
142: raise LoadError unless filename
143: path = filename
144: elsif File.directory?(path)
145: raise LoadError unless filename
146: path = File.join(path, filename)
147: end
148: if file = Dir.glob(path, File::FNM_CASEFOLD)[0]
149: File.expand_path(file)
150: else
151: raise Errno::ENOENT
152: end
153: 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
103: def load(path_or_data)
104: case path_or_data
105: when File
106: open(path_or_data.path)
107: when Pathname
108: open(path_or_data.realpath)
109: else
110: new(path_or_data)
111: end
112: end
Locate file (case insensitive).
# File lib/more/facets/fileable.rb, line 123
123: def locate(name=nil)
124: name ||= filename
125: raise LoadError unless name
126: Dir.ascend(Dir.pwd) do |dir|
127: match = File.join(dir, name)
128: files = Dir.glob(match, File::FNM_CASEFOLD)
129: if file = files[0]
130: return file
131: end
132: end
133: return nil
134: end