Module: Fileable::DSL

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

### Methods

file filename included load load_cache locate lookup open

### Public Instance methods

file(path=nil)

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
        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

filename()

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
        def filename; nil; end

included(base)

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
        def included(base)
          base.extend DSL
        end

load(path_or_data)

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
        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()

Load cache. PackageInfo is multiton when loaded by file.

[Source]

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

locate(name=nil)

Locate file (case insensitive).

[Source]

    # 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

lookup(name=nil)

Lookup file.

[Source]

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

open(path=nil)

Load from file(s).

[Source]

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

[Validate]