In Files
Parent
- Object
Methods
Included Modules
- Enumerable
Information
Lookup
The Lookup class provides a table of paths which make it easy to quickly populate and refresh the environment index.
Public Class Methods
Public Instance Methods
append(path, depth=3)
click to toggle source
# File lib/roll/environment.rb, line 245
245: def append(path, depth=3)
246: path = File.expand_path(path)
247: depth = (depth || 3).to_i
248: @table = @table.reject{ |(p, d)| path == p }
249: @table.push([path, depth])
250: end
delete(path)
click to toggle source
# File lib/roll/environment.rb, line 253
253: def delete(path)
254: @table.reject!{ |p,d| path == p }
255: end
each(&block)
click to toggle source
# File lib/roll/environment.rb, line 235
235: def each(&block)
236: @table.each(&block)
237: end
file()
click to toggle source
# File lib/roll/environment.rb, line 211
211: def file
212: @file ||= ::Config.find_config('roll', name, 'lookup').first
213: end
find_projects(dir, depth=3)
click to toggle source
Search a given directory for projects upto a given depth. Projects directories are determined by containing a ‘meta’ or ’.meta’ directory.
# File lib/roll/environment.rb, line 296
296: def find_projects(dir, depth=3)
297: depth = Integer(depth || 3)
298: depth = (0...depth).map{ |i| (["*"] * i).join('/') }.join(',')
299: glob = File.join(dir, "{#{depth}}", "{.meta,meta}")
300: meta_locations = Dir[glob]
301: meta_locations.map{ |d| d.chomp('/meta').chomp('/.meta') }
302: end
index()
click to toggle source
Generate index from lookup list.
# File lib/roll/environment.rb, line 272
272: def index
273: set = Hash.new{ |h,k| h[k] = [] }
274: locate.each do |path|
275: name = load_name(path)
276: #vers = load_version(path)
277: if name #&& vers
278: set[name] << path
279: end
280: end
281: set
282: end
load_name(path)
click to toggle source
Get library name.
# File lib/roll/environment.rb, line 305
305: def load_name(path)
306: file = Dir[File.join(path, '{,.}meta', 'name')].first
307: if file
308: File.read(file).strip # TODO: handle YAML
309: end
310: end
locate()
click to toggle source
# File lib/roll/environment.rb, line 285
285: def locate
286: locs = []
287: each do |dir, depth|
288: locs << find_projects(dir, depth)
289: end
290: locs.flatten
291: end
name()
click to toggle source
# File lib/roll/environment.rb, line 206
206: def name
207: @name
208: end
reload()
click to toggle source
# File lib/roll/environment.rb, line 216
216: def reload
217: t = []
218: if file && File.exist?(file)
219: lines = File.readlines(file)
220: lines.each do |line|
221: line = line.strip
222: path, depth = *line.split(/\s+/)
223: next if line =~ /^\s*$/ # blank
224: next if line =~ /^\#/ # comment
225: dir, depth = *line.split(/\s+/)
226: t << [path, (depth || 3).to_i]
227: end
228: else
229: t = []
230: end
231: @table = t
232: end
save()
click to toggle source
# File lib/roll/environment.rb, line 258
258: def save
259: file = File.join(::Config::CONFIG_HOME, 'roll', name, 'lookup')
260: out = @table.map do |(path, depth)|
261: "#{path} #{depth}"
262: end
263: dir = File.dirname(file)
264: FileUtils.mkdir_p(dir) unless File.exist?(dir)
265: File.open(file, 'w') do |f|
266: f << out.join("\n")
267: end
268: @file = file
269: end
Disabled; run with --debug to generate this.