Class Tap::Tasks::List
In: lib/tap/tasks/list.rb
Parent: Dump

Prints a list of resources registered with the application env. Any of the resources may be used in a workflow. A list of filters may be used to limit the output; each is converted to a regexp and can match any part of the resource (path, class, desc).

  % tap list join gate
  join:
    gate                 # collects results before the join

The configurations can be used to switch the resource description. By default env only lists resources registered as a task, join, or middleware.

  % tap list join gate --class --full
  join:
    /tap/joins/gate      # Tap::Joins::Gate

Methods

basis   call   describe   filter   fullmap   load_path   manifest   max_width   minimap   split   types  

Configurations

all  [RW]  Shows all types (false)
clas  [RW]  (false)
full  [RW]  Show full paths (false)
path  [RW]  Show require path (false)
types  [RW]  ([)

Public Instance methods

[Source]

    # File lib/tap/tasks/list.rb, line 42
42:       def basis
43:         app.env.constants
44:       end

[Source]

    # File lib/tap/tasks/list.rb, line 38
38:       def call(input)
39:         process manifest(*input).join("\n")
40:       end

[Source]

     # File lib/tap/tasks/list.rb, line 155
155:       def describe(constant, type)
156:         case
157:         when clas 
158:           constant.const_name
159:           
160:         when path
161:           require_paths = constant.require_paths
162:           require_paths = require_paths.collect do |path|
163:             File.join(load_path(path), path)
164:           end if full
165:           require_paths.join(',')
166:           
167:         else 
168:           constant.types[type]
169:         end
170:       end

[Source]

     # File lib/tap/tasks/list.rb, line 100
100:       def filter(constants, filters)
101:         return constants if filters.empty?
102:         
103:         filters.collect! {|filter| Regexp.new(filter) }
104:         constants = constants.select do |constant|
105:           filters.all? do |filter|
106:             constant.path =~ filter
107:           end
108:         end
109:       end

[Source]

     # File lib/tap/tasks/list.rb, line 111
111:       def fullmap(constants)
112:         paths = {}
113:         constants.each {|constant| paths[constant] = constant.path }
114:         paths
115:       end

[Source]

     # File lib/tap/tasks/list.rb, line 172
172:       def load_path(path)
173:         $:.find do |load_path|
174:           File.exists?(File.join(load_path, path))
175:         end || '?'
176:       end

[Source]

    # File lib/tap/tasks/list.rb, line 58
58:       def manifest(*filters)
59:         constants = filter(basis, filters)
60:         
61:         paths = full ? fullmap(constants) : minimap(constants)
62:         constants = constants.sort_by {|constant| paths[constant] }
63:         
64:         descriptions = {}
65:         selected_paths = []
66:         selected_types = types
67:         
68:         selected_types.each do |type|
69:           lines = []
70:           constants.each do |constant|
71:             next unless constant.types.include?(type)
72:             
73:             path = paths[constant]
74:             selected_paths << path
75:             lines << [path, describe(constant, type)]
76:           end
77:           
78:           descriptions[type] = lines unless lines.empty?
79:         end
80:         
81:         format = "  %-#{max_width(selected_paths)}s # %s"
82:         
83:         lines = []
84:         selected_types.each do |type|
85:           next unless descriptions.has_key?(type)
86:           
87:           lines << "#{type}:"
88:           descriptions[type].each do |description|
89:             lines << (format % description)
90:           end
91:         end
92:         
93:         if lines.empty?
94:           lines << "(no constants match criteria)"
95:         end
96:         
97:         lines
98:       end

[Source]

     # File lib/tap/tasks/list.rb, line 178
178:       def max_width(paths)
179:         max = paths.collect {|path| path.length }.max
180:         max.nil? || max < 20 ? 20 : max
181:       end

[Source]

     # File lib/tap/tasks/list.rb, line 117
117:       def minimap(constants)
118:         paths = {}
119:         constants.each do |constant|
120:           paths[constant] = split(constant.path)
121:         end
122:         
123:         minimap = {}
124:         queue = constants.dup
125:         while !queue.empty?
126:           next_queue = []
127:           queue.each do |constant|
128:             path = paths[constant].shift
129:             
130:             if current = minimap[path]
131:               next_queue << current unless current == :skip
132:               next_queue << constant
133:               minimap[path] = :skip
134:             else
135:               minimap[path] = constant
136:             end
137:           end
138:           
139:           queue = next_queue
140:         end
141:         
142:         minimap.delete_if {|path, constant| constant == :skip }.invert
143:       end

[Source]

     # File lib/tap/tasks/list.rb, line 145
145:       def split(path)
146:         splits = []
147:         current = nil
148:         path.split('/').reverse_each do |split|
149:           current = current ? File.join(split, current) : split
150:           splits << current
151:         end
152:         splits
153:       end

[Source]

    # File lib/tap/tasks/list.rb, line 46
46:       def types
47:         return @types unless all
48:         
49:         types = []
50:         app.env.constants.each do |constant|
51:           types.concat constant.types.keys
52:         end
53:         types.uniq!
54:         types.sort!
55:         types
56:       end

[Validate]