Class: Bundler::Repository
- Inherits:
-
Object
- Object
- Bundler::Repository
- Defined in:
- lib/bundler/repository.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #cache(*gemfiles) ⇒ Object
- #download_path_for(type) ⇒ Object
- #gems ⇒ Object
-
#initialize(path, bindir) ⇒ Repository
constructor
A new instance of Repository.
- #install(dependencies, sources, options = {}) ⇒ Object
- #outdated_gems ⇒ Object
- #prune(dependencies, sources) ⇒ Object
- #source_index ⇒ Object
Constructor Details
#initialize(path, bindir) ⇒ Repository
Returns a new instance of Repository.
7 8 9 10 11 12 13 14 |
# File 'lib/bundler/repository.rb', line 7 def initialize(path, bindir) FileUtils.mkdir_p(path) @path = Pathname.new(path) @bindir = Pathname.new(bindir) @cache = GemDirectorySource.new(:location => @path.join("cache")) end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/bundler/repository.rb', line 5 def path @path end |
Instance Method Details
#cache(*gemfiles) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/bundler/repository.rb', line 53 def cache(*gemfiles) FileUtils.mkdir_p(@path.join("cache")) gemfiles.each do |gemfile| Bundler.logger.info "Caching: #{File.basename(gemfile)}" FileUtils.cp(gemfile, @path.join("cache")) end end |
#download_path_for(type) ⇒ Object
93 94 95 |
# File 'lib/bundler/repository.rb', line 93 def download_path_for(type) @repos[type].download_path_for end |
#gems ⇒ Object
79 80 81 |
# File 'lib/bundler/repository.rb', line 79 def gems source_index.gems.values end |
#install(dependencies, sources, options = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/bundler/repository.rb', line 16 def install(dependencies, sources, = {}) # TODO: clean this up sources.each do |s| s.repository = self s.local = [:cached] end source_requirements = {} dependencies = dependencies.map do |dep| source_requirements[dep.name] = dep.source if dep.source dep.to_gem_dependency end # Check to see whether the existing cache meets all the requirements begin valid = nil # valid = Resolver.resolve(dependencies, [source_index], source_requirements) rescue Bundler::GemNotFound end sources = only_local(sources) if [:cached] # Check the remote sources if the existing cache does not meet the requirements # or the user passed --update if [:update] || !valid Bundler.logger.info "Calculating dependencies..." bundle = Resolver.resolve(dependencies, [@cache] + sources, source_requirements) download(bundle, ) do_install(bundle, ) valid = bundle end generate_bins(valid, ) cleanup(valid, ) configure(valid, ) end |
#outdated_gems ⇒ Object
83 84 85 |
# File 'lib/bundler/repository.rb', line 83 def outdated_gems source_index.outdated.sort end |
#prune(dependencies, sources) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/bundler/repository.rb', line 61 def prune(dependencies, sources) sources.each do |s| s.repository = self s.local = true end sources = only_local(sources) bundle = Resolver.resolve(dependencies, [@cache] + sources) @cache.gems.each do |name, specs| specs.each do |spec| unless bundle.any? { |s| s.name == spec.name && s.version == spec.version } Bundler.logger.info "Pruning #{spec.name} (#{spec.version}) from the cache" FileUtils.rm @path.join("cache", "#{spec.full_name}.gem") end end end end |
#source_index ⇒ Object
87 88 89 90 91 |
# File 'lib/bundler/repository.rb', line 87 def source_index index = Gem::SourceIndex.from_gems_in(@path.join("specifications")) index.each { |n, spec| spec.loaded_from = @path.join("specifications", "#{spec.full_name}.gemspec") } index end |