Class: Arborist::Loader::File
- Inherits:
-
Arborist::Loader
- Object
- Arborist::Loader
- Arborist::Loader::File
- Defined in:
- lib/arborist/loader/file.rb
Overview
A loader for Arborist that knows how to load stuff from files on disk.
Constant Summary collapse
- FILE_PATTERN =
The glob pattern to use for searching for files
'**/*.rb'
Instance Attribute Summary collapse
-
#directory ⇒ Object
readonly
The directory to load files from.
Instance Method Summary collapse
-
#enumerator_for(arborist_class) ⇒ Object
Return an Enumerator that will instantiate and yield instances of the specified
arborist_class
for each file path in the loader’s directory. -
#initialize(directory) ⇒ File
constructor
Create a new loader that will read nodes from the specified
directory
. -
#monitors ⇒ Object
Return an Enumerator that yields Arborist::Monitors loaded from the target directory.
-
#nodes ⇒ Object
Return an Enumerator that yields Arborist::Nodes loaded from the target directory.
-
#observers ⇒ Object
Return an Enumerator that yields Arborist::Observers loaded from the target directory.
-
#paths ⇒ Object
Return an Enumerator.
Constructor Details
#initialize(directory) ⇒ File
Create a new loader that will read nodes from the specified directory
.
16 17 18 19 |
# File 'lib/arborist/loader/file.rb', line 16 def initialize( directory ) Arborist.load_all @directory = directory end |
Instance Attribute Details
#directory ⇒ Object (readonly)
The directory to load files from
23 24 25 |
# File 'lib/arborist/loader/file.rb', line 23 def directory @directory end |
Instance Method Details
#enumerator_for(arborist_class) ⇒ Object
Return an Enumerator that will instantiate and yield instances of the specified arborist_class
for each file path in the loader’s directory.
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/arborist/loader/file.rb', line 60 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. ] yielder.yield( object ) end end end end |
#monitors ⇒ Object
Return an Enumerator that yields Arborist::Monitors loaded from the target directory.
46 47 48 |
# File 'lib/arborist/loader/file.rb', line 46 def monitors return self.enumerator_for( Arborist::Monitor ) end |
#nodes ⇒ Object
Return an Enumerator that yields Arborist::Nodes loaded from the target directory.
39 40 41 |
# File 'lib/arborist/loader/file.rb', line 39 def nodes return self.enumerator_for( Arborist::Node ) end |
#observers ⇒ Object
Return an Enumerator that yields Arborist::Observers loaded from the target directory.
53 54 55 |
# File 'lib/arborist/loader/file.rb', line 53 def observers return self.enumerator_for( Arborist::Observer ) end |
#paths ⇒ Object
Return an Enumerator
27 28 29 30 31 32 33 34 |
# File 'lib/arborist/loader/file.rb', line 27 def paths path = Pathname( self.directory ) if path.directory? return Pathname.glob( path + FILE_PATTERN ).each else return [ path ].each end end |