A loader for Arborist that knows how to load stuff from files on disk.
The glob pattern to use for searching for files
The directory to load files from
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
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
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
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
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
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