Class: Root::ConstantManifest
- Defined in:
- lib/root/constant_manifest.rb
Overview
:startdoc:::-
ConstantManifest builds a manifest of Constant entries using Lazydoc.
Lazydoc can quickly scan files for constant attributes, and thereby identify constants based upon a flag like the ‘::manifest’ attribute used to identify task classes. ConstantManifest registers paths that will be scanned for a specific resource, and lazily builds the references to load them as necessary.
:startdoc:::+
Constant Summary
Constants inherited from Manifest
Instance Attribute Summary collapse
-
#const_attr ⇒ Object
readonly
The attribute identifying constants in a file.
-
#path_index ⇒ Object
readonly
The current index of paths.
-
#search_path_index ⇒ Object
readonly
The current index of search_paths.
-
#search_paths ⇒ Object
readonly
An array of registered (root, [paths]) pairs that will be searched for const_attr.
Attributes inherited from Manifest
Instance Method Summary collapse
-
#build ⇒ Object
Searches all paths for entries and adds them to self.
-
#built? ⇒ Boolean
True if there are no more paths to search (ie search_path_index == search_paths.length).
-
#each ⇒ Object
Yields each Constant entry to the block.
-
#initialize(const_attr) ⇒ ConstantManifest
constructor
Initializes a new ConstantManifest that will identify constants using the specified constant attribute.
-
#register(dir, pattern) ⇒ Object
Registers the files matching pattern under dir.
-
#reset ⇒ Object
Sets search_path_index and path_index to zero and clears entries.
Methods inherited from Manifest
#[], #bind, #bound?, #empty?, #inspect, intern, #search, #unbind
Methods included from Minimap
Constructor Details
#initialize(const_attr) ⇒ ConstantManifest
Initializes a new ConstantManifest that will identify constants using the specified constant attribute.
36 37 38 39 40 41 42 |
# File 'lib/root/constant_manifest.rb', line 36 def initialize(const_attr) @const_attr = const_attr @search_paths = [] @search_path_index = 0 @path_index = 0 super([]) end |
Instance Attribute Details
#const_attr ⇒ Object (readonly)
The attribute identifying constants in a file
22 23 24 |
# File 'lib/root/constant_manifest.rb', line 22 def const_attr @const_attr end |
#path_index ⇒ Object (readonly)
The current index of paths
32 33 34 |
# File 'lib/root/constant_manifest.rb', line 32 def path_index @path_index end |
#search_path_index ⇒ Object (readonly)
The current index of search_paths
29 30 31 |
# File 'lib/root/constant_manifest.rb', line 29 def search_path_index @search_path_index end |
#search_paths ⇒ Object (readonly)
An array of registered (root, [paths]) pairs that will be searched for const_attr
26 27 28 |
# File 'lib/root/constant_manifest.rb', line 26 def search_paths @search_paths end |
Instance Method Details
#build ⇒ Object
Searches all paths for entries and adds them to self. Returns self.
52 53 54 55 |
# File 'lib/root/constant_manifest.rb', line 52 def build each {|entry| } unless built? self end |
#built? ⇒ Boolean
True if there are no more paths to search (ie search_path_index == search_paths.length)
59 60 61 |
# File 'lib/root/constant_manifest.rb', line 59 def built? search_path_index == search_paths.length end |
#each ⇒ Object
Yields each Constant entry to the block. Unless built?, each lazily iterates over search_paths to look for new entries.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/root/constant_manifest.rb', line 75 def each entries.each do |entry| yield(entry) end search_paths[search_path_index, search_paths.length - search_path_index].each do |(path_root, paths)| paths[path_index, paths.length - path_index].each do |path| new_entries = resolve(path_root, path) entries.concat(new_entries) @path_index += 1 new_entries.each {|entry| yield(entry) } end @search_path_index += 1 @path_index = 0 end unless built? end |
#register(dir, pattern) ⇒ Object
Registers the files matching pattern under dir. Returns self.
45 46 47 48 49 |
# File 'lib/root/constant_manifest.rb', line 45 def register(dir, pattern) paths = Dir.glob(File.join(dir, pattern)).select {|file| File.file?(file) } search_paths << [dir, paths.sort] self end |
#reset ⇒ Object
Sets search_path_index and path_index to zero and clears entries. Returns self.
65 66 67 68 69 70 71 |
# File 'lib/root/constant_manifest.rb', line 65 def reset @search_paths.each {|path| Lazydoc[path].resolved = false } @entries.clear @search_path_index = 0 @path_index = 0 super end |