Class Tap::Env::Cache
In: lib/tap/env/cache.rb
Parent: Object

Methods

generate   new   search   select  

Attributes

cache_home  [R] 

Public Class methods

[Source]

    # File lib/tap/env/cache.rb, line 10
10:       def initialize(dir=Dir.pwd, debug=false)
11:         @cache_home = File.expand_path("#{RbConfig::CONFIG['RUBY_INSTALL_NAME']}/#{RUBY_VERSION}", dir)
12:         @debug = debug
13:       end

Public Instance methods

[Source]

    # File lib/tap/env/cache.rb, line 73
73:       def generate(spec)
74:         lines = Env.generate(
75:           :dir => spec.full_gem_path, 
76:           :pathfile => File.expand_path(Path::FILE, spec.full_gem_path),
77:           :load_paths => false)
78:         
79:         lines.unshift "# Generated for #{spec.full_name} on #{Time.now}.  Do not edit."
80:         lines << "activate #{spec.name} #{spec.version}"
81:         lines.uniq!
82:         lines.sort!
83:         lines.join("\n")
84:       end

[Source]

    # File lib/tap/env/cache.rb, line 32
32:       def search(pattern, version_requirements)
33:         dependency = Gem::Dependency.new(pattern, version_requirements)
34:         
35:         sources = {}
36:         Gem.source_index.search(dependency).sort_by do |spec|
37:           spec.version
38:         end.reverse_each do |spec|
39:           sources[spec.name] ||= spec
40:         end
41:         
42:         paths = []
43:         sources.values.sort_by do |spec|
44:           spec.name
45:         end.each do |spec|
46:           unless File.exists? File.expand_path(Path::FILE, spec.full_gem_path)
47:             next
48:           end
49:           
50:           path = File.join(cache_home, spec.full_name)
51:           gem_path = spec.full_gem_path
52:           
53:           unless FileUtils.uptodate?(path, [gem_path, __FILE__])
54:             unless File.exists?(cache_home)
55:               FileUtils.mkdir_p(cache_home)
56:             end
57:             
58:             if @debug 
59:               $stderr.puts(App::LOG_FORMAT % [' ', nil, :generate, spec.full_name])
60:             end
61:             
62:             File.open(path, 'w') do |io|
63:               io << generate(spec)
64:             end
65:           end
66:           
67:           paths << path
68:         end
69:         
70:         paths
71:       end

[Source]

    # File lib/tap/env/cache.rb, line 15
15:       def select(dependencies)
16:         if dependencies.kind_of?(String)
17:           dependencies = dependencies.split(':')
18:         end
19:         
20:         paths = []
21:         dependencies.collect! do |dep|
22:           dep.kind_of?(String) ? dep.split(',', 2) : dep
23:         end.each do |(pattern, version_requirements)|
24:           pattern = Regexp.new(pattern) if pattern.kind_of?(String)
25:           paths.concat search(pattern, version_requirements)
26:         end
27:         
28:         paths.uniq!
29:         paths
30:       end

[Validate]