Class: Tap::Env::Cache
- Inherits:
-
Object
- Object
- Tap::Env::Cache
- Defined in:
- lib/tap/env/cache.rb
Instance Attribute Summary collapse
-
#cache_home ⇒ Object
readonly
Returns the value of attribute cache_home.
Instance Method Summary collapse
- #generate(spec) ⇒ Object
-
#initialize(dir = Dir.pwd, debug = false) ⇒ Cache
constructor
A new instance of Cache.
- #search(pattern, version_requirements) ⇒ Object
- #select(dependencies) ⇒ Object
Constructor Details
#initialize(dir = Dir.pwd, debug = false) ⇒ Cache
Returns a new instance of Cache.
10 11 12 13 |
# File 'lib/tap/env/cache.rb', line 10 def initialize(dir=Dir.pwd, debug=false) @cache_home = File.("#{RbConfig::CONFIG['RUBY_INSTALL_NAME']}/#{RUBY_VERSION}", dir) @debug = debug end |
Instance Attribute Details
#cache_home ⇒ Object (readonly)
Returns the value of attribute cache_home.
8 9 10 |
# File 'lib/tap/env/cache.rb', line 8 def cache_home @cache_home end |
Instance Method Details
#generate(spec) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/tap/env/cache.rb', line 73 def generate(spec) lines = Env.generate( :dir => spec.full_gem_path, :pathfile => File.(Path::FILE, spec.full_gem_path), :load_paths => false) lines.unshift "# Generated for #{spec.full_name} on #{Time.now}. Do not edit." lines << "activate #{spec.name} #{spec.version}" lines.uniq! lines.sort! lines.join("\n") end |
#search(pattern, version_requirements) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/tap/env/cache.rb', line 32 def search(pattern, version_requirements) dependency = Gem::Dependency.new(pattern, version_requirements) sources = {} Gem.source_index.search(dependency).sort_by do |spec| spec.version end.reverse_each do |spec| sources[spec.name] ||= spec end paths = [] sources.values.sort_by do |spec| spec.name end.each do |spec| unless File.exists? File.(Path::FILE, spec.full_gem_path) next end path = File.join(cache_home, spec.full_name) gem_path = spec.full_gem_path unless FileUtils.uptodate?(path, [gem_path, __FILE__]) unless File.exists?(cache_home) FileUtils.mkdir_p(cache_home) end if @debug $stderr.puts(App::LOG_FORMAT % [' ', nil, :generate, spec.full_name]) end File.open(path, 'w') do |io| io << generate(spec) end end paths << path end paths end |
#select(dependencies) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/tap/env/cache.rb', line 15 def select(dependencies) if dependencies.kind_of?(String) dependencies = dependencies.split(':') end paths = [] dependencies.collect! do |dep| dep.kind_of?(String) ? dep.split(',', 2) : dep end.each do |(pattern, version_requirements)| pattern = Regexp.new(pattern) if pattern.kind_of?(String) paths.concat search(pattern, version_requirements) end paths.uniq! paths end |