class Arborist::Loader::File
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
new( directory )
click to toggle source
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
enumerator_for( arborist_class )
click to toggle source
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
monitors()
click to toggle source
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
nodes()
click to toggle source
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
observers()
click to toggle source
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
paths()
click to toggle source
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