File

class
Superclass
Arborist::Loader

A loader for Arborist that knows how to load stuff from files on disk.

Constants

FILE_PATTERN

The glob pattern to use for searching for files

Attributes

directory[R]

The directory to load files from

Public Class Methods

anchor
new( directory )

Create a new loader that will read nodes from the specified directory.

# File lib/arborist/loader/file.rb, line 15
def initialize( directory )
        Arborist.load_all
        @directory = directory
end

Public Instance Methods

anchor
enumerator_for( arborist_class )

Return an Enumerator that will instantiate and yield instances of the specified arborist_class for each file path in the loader's directory.

# File lib/arborist/loader/file.rb, line 59
def enumerator_for( arborist_class )
        return Enumerator.new do |yielder|
                self.paths.each do |file|
                        objects = arborist_class.load( file )
                        objects.each do |object|
                                object.source = "file://%s" % [ file.expand_path ]
                                yielder.yield( object )
                        end
                end
        end
end
anchor
monitors()

Return an Enumerator that yields Arborist::Monitors loaded from the target directory.

# File lib/arborist/loader/file.rb, line 45
def monitors
        return self.enumerator_for( Arborist::Monitor )
end
anchor
nodes()

Return an Enumerator that yields Arborist::Nodes loaded from the target directory.

# File lib/arborist/loader/file.rb, line 38
def nodes
        return self.enumerator_for( Arborist::Node )
end
anchor
observers()

Return an Enumerator that yields Arborist::Observers loaded from the target directory.

# File lib/arborist/loader/file.rb, line 52
def observers
        return self.enumerator_for( Arborist::Observer )
end
anchor
paths()

Return an Enumerator

# File lib/arborist/loader/file.rb, line 26
def paths
        path = Pathname( self.directory )
        if path.directory?
                return Pathname.glob( path + FILE_PATTERN ).each
        else
                return [ path ].each
        end
end