Class: Tap::Support::ConstantManifest

Inherits:
Manifest show all
Defined in:
lib/tap/support/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 a manifest of Constant references to load them as necessary.

:startdoc:::+

Constant Summary

Constants inherited from Manifest

Manifest::SEARCH_REGEXP

Instance Attribute Summary collapse

Attributes inherited from Manifest

#entries, #env, #reader

Instance Method Summary collapse

Methods inherited from Manifest

#[], #bind, #bound?, #empty?, #inspect, intern, #search, #unbind

Methods included from Minimap

#minimap, #minimatch

Constructor Details

#initialize(const_attr) ⇒ ConstantManifest

Initializes a new ConstantManifest that will identify constants using the specified constant attribute.



35
36
37
38
39
40
41
# File 'lib/tap/support/constant_manifest.rb', line 35

def initialize(const_attr)
  @const_attr = const_attr
  @search_paths = []
  @search_path_index = 0
  @path_index = 0
  super([])
end

Instance Attribute Details

#const_attrObject (readonly)

The attribute identifying constants in a file



21
22
23
# File 'lib/tap/support/constant_manifest.rb', line 21

def const_attr
  @const_attr
end

#path_indexObject (readonly)

The current index of paths



31
32
33
# File 'lib/tap/support/constant_manifest.rb', line 31

def path_index
  @path_index
end

#search_path_indexObject (readonly)

The current index of search_paths



28
29
30
# File 'lib/tap/support/constant_manifest.rb', line 28

def search_path_index
  @search_path_index
end

#search_pathsObject (readonly)

An array of registered [root, [paths]] pairs that will be searched for const_attr



25
26
27
# File 'lib/tap/support/constant_manifest.rb', line 25

def search_paths
  @search_paths
end

Instance Method Details

#buildObject

Searches all paths for entries and adds them to self. Returns self.



51
52
53
54
# File 'lib/tap/support/constant_manifest.rb', line 51

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)

Returns:

  • (Boolean)


58
59
60
# File 'lib/tap/support/constant_manifest.rb', line 58

def built?
  search_path_index == search_paths.length
end

#eachObject

Yields each entry to the block. Unless built?, each lazily iterates over search_paths to look for new entries.



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/tap/support/constant_manifest.rb', line 74

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.



44
45
46
47
48
# File 'lib/tap/support/constant_manifest.rb', line 44

def register(dir, pattern)
  paths = Dir.glob(File.join(dir, pattern)).select {|file| File.file?(file) }
  search_paths << [dir, paths.sort]
  self
end

#resetObject

Sets search_path_index and path_index to zero and clears entries. Returns self.



64
65
66
67
68
69
70
# File 'lib/tap/support/constant_manifest.rb', line 64

def reset
  # Support::Lazydoc[path].resolved = false
  @entries.clear
  @search_path_index = 0
  @path_index = 0
  super
end