Module Fileable::DSL
In: lib/more/facets/fileable.rb

Methods

file   filename   included   load   load_cache   locate   lookup   open  

Public Instance methods

Find file. The path has to be either the exact path or the directory where a standard-named file resides.

[Source]

     # 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

Override this with the name or name-glob of the default file. If no default, return nil.

[Source]

    # File lib/more/facets/fileable.rb, line 86
86:     def filename; nil; end

While this doesn‘t allpy to classes, for modules it is needed to keep the DSL inheritance going.

[Source]

    # File lib/more/facets/fileable.rb, line 79
79:     def included(base)
80:       base.extend DSL
81:     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.

[Source]

     # 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

Load cache. PackageInfo is multiton when loaded by file.

[Source]

     # File lib/more/facets/fileable.rb, line 157
157:     def load_cache
158:       @load_cache ||= {}
159:     end

Locate file (case insensitive).

[Source]

     # 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

Lookup file.

[Source]

     # File lib/more/facets/fileable.rb, line 116
116:     def lookup(name=nil)
117:       file = locate(name)
118:       file ? open(file) : nil #raise LoadError
119:     end

Load from file(s).

[Source]

    # File lib/more/facets/fileable.rb, line 90
90:     def open(path=nil)
91:       file = file(path)
92:       if file
93:         fobj = new
94:         fobj.send(:read, file)
95:         return fobj
96:       end
97:     end

[Validate]