Class: Tap::Support::ConstantManifest

Inherits:
Manifest show all
Defined in:
lib/tap/support/constant_manifest.rb

Overview

ConstantManifest builds a manifest of Constant entries using Lazydoc. The idea is that Lazydoc can find files with resouces of a specific type (ex tasks) and Constant can reference those resouces and load them as necessary. ConstantManifest registers paths so that they may be lazily scanned when searching for a specific resource.

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



28
29
30
31
32
33
34
# File 'lib/tap/support/constant_manifest.rb', line 28

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 resources in a file



15
16
17
# File 'lib/tap/support/constant_manifest.rb', line 15

def const_attr
  @const_attr
end

#path_indexObject (readonly)

The current index of paths



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

def path_index
  @path_index
end

#search_path_indexObject (readonly)

The current index of search_paths



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

def search_path_index
  @search_path_index
end

#search_pathsObject (readonly)

Registered [root, [paths]] pairs that will be searched for the const_attr



19
20
21
# File 'lib/tap/support/constant_manifest.rb', line 19

def search_paths
  @search_paths
end

Instance Method Details

#buildObject

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



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

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)


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

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.



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/tap/support/constant_manifest.rb', line 67

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.



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

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.



57
58
59
60
61
62
63
# File 'lib/tap/support/constant_manifest.rb', line 57

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