Class: Bundler::Bundle
- Inherits:
-
Object
- Object
- Bundler::Bundle
- Defined in:
- lib/bowline/bundler/bundle.rb
Instance Attribute Summary collapse
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#gemfile ⇒ Object
readonly
Returns the value of attribute gemfile.
Class Method Summary collapse
Instance Method Summary collapse
- #bindir ⇒ Object
- #bindir=(path) ⇒ Object
- #cache(*gemfiles) ⇒ Object
- #download_path_for(type) ⇒ Object
- #gem_path ⇒ Object
- #gems ⇒ Object
-
#initialize(gemfile) ⇒ Bundle
constructor
TODO: passing in the filename is not good.
- #install(options = {}) ⇒ Object
- #list(options = {}) ⇒ Object
- #list_outdated(options = {}) ⇒ Object
- #path ⇒ Object
- #path=(path) ⇒ Object
- #prune(options = {}) ⇒ Object
- #root ⇒ Object
- #setup_environment ⇒ Object
- #source_index ⇒ Object
Constructor Details
#initialize(gemfile) ⇒ Bundle
TODO: passing in the filename is not good
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/bowline/bundler/bundle.rb', line 30 def initialize(gemfile) @gemfile = gemfile @environment = Environment.new(self) Dsl.evaluate(gemfile, self, @environment) # path = env.gem_path FileUtils.mkdir_p(gem_path) @cache_path = gem_path.join('cache') @cache = GemDirectorySource.new(self, :location => @cache_path) @specs_path = gem_path.join('specifications') @gems_path = gem_path.join('gems') end |
Instance Attribute Details
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
5 6 7 |
# File 'lib/bowline/bundler/bundle.rb', line 5 def environment @environment end |
#gemfile ⇒ Object (readonly)
Returns the value of attribute gemfile.
5 6 7 |
# File 'lib/bowline/bundler/bundle.rb', line 5 def gemfile @gemfile end |
Class Method Details
.default_gemfile ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/bowline/bundler/bundle.rb', line 17 def self.default_gemfile current = Pathname.new(Dir.pwd) until current.root? filename = current.join("Gemfile") return filename if filename.exist? current = current.parent end raise DefaultManifestNotFound end |
.load(gemfile = nil) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/bowline/bundler/bundle.rb', line 7 def self.load(gemfile = nil) gemfile = Pathname.new(gemfile || default_gemfile). unless gemfile.file? raise ManifestFileNotFound, "Manifest file not found: #{gemfile.to_s.inspect}" end new(gemfile) end |
Instance Method Details
#bindir ⇒ Object
62 63 64 |
# File 'lib/bowline/bundler/bundle.rb', line 62 def bindir @bindir ||= root.join("bin") end |
#bindir=(path) ⇒ Object
66 67 68 |
# File 'lib/bowline/bundler/bundle.rb', line 66 def bindir=(path) @bindir = (path.relative? ? root.join(path) : path). end |
#cache(*gemfiles) ⇒ Object
111 112 113 114 115 116 117 |
# File 'lib/bowline/bundler/bundle.rb', line 111 def cache(*gemfiles) FileUtils.mkdir_p(@cache_path) gemfiles.each do |gemfile| Bundler.logger.info "Caching: #{File.basename(gemfile)}" FileUtils.cp(gemfile, @cache_path) end end |
#download_path_for(type) ⇒ Object
168 169 170 |
# File 'lib/bowline/bundler/bundle.rb', line 168 def download_path_for(type) @repos[type].download_path_for end |
#gem_path ⇒ Object
58 59 60 |
# File 'lib/bowline/bundler/bundle.rb', line 58 def gem_path path.join("#{Gem.ruby_engine}/#{Gem::ConfigMap[:ruby_version]}") end |
#gems ⇒ Object
158 159 160 |
# File 'lib/bowline/bundler/bundle.rb', line 158 def gems source_index.gems.values end |
#install(options = {}) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/bowline/bundler/bundle.rb', line 70 def install( = {}) dependencies = @environment.dependencies sources = @environment.sources # ========== from env if only_envs = [:only] dependencies.reject! { |d| !only_envs.any? {|env| d.in?(env) } } end # ========== # TODO: clean this up sources.each do |s| s.local = [:cached] 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) download(bundle, ) do_install(bundle, ) valid = bundle end generate_bins(valid, ) cleanup(valid, ) configure(valid, ) Bundler.logger.info "Done." end |
#list(options = {}) ⇒ Object
151 152 153 154 155 156 |
# File 'lib/bowline/bundler/bundle.rb', line 151 def list( = {}) Bundler.logger.info "Currently bundled gems:" gems.each do |spec| Bundler.logger.info " * #{spec.name} (#{spec.version})" end end |
#list_outdated(options = {}) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/bowline/bundler/bundle.rb', line 119 def list_outdated(={}) outdated_gems = source_index.outdated.sort if outdated_gems.empty? Bundler.logger.info "All gems are up to date." else Bundler.logger.info "Outdated gems:" outdated_gems.each do |name| Bundler.logger.info " * #{name}" end end end |
#path ⇒ Object
50 51 52 |
# File 'lib/bowline/bundler/bundle.rb', line 50 def path @path ||= root.join("vendor/gems") end |
#path=(path) ⇒ Object
54 55 56 |
# File 'lib/bowline/bundler/bundle.rb', line 54 def path=(path) @path = (path.relative? ? root.join(path) : path). end |
#prune(options = {}) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/bowline/bundler/bundle.rb', line 132 def prune( = {}) dependencies, sources = @environment.gem_dependencies, @environment.sources sources.each do |s| 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 @cache_path.join("#{spec.full_name}.gem") end end end end |
#root ⇒ Object
46 47 48 |
# File 'lib/bowline/bundler/bundle.rb', line 46 def root gemfile.parent end |
#setup_environment ⇒ Object
172 173 174 175 176 177 178 179 |
# File 'lib/bowline/bundler/bundle.rb', line 172 def setup_environment unless @environment.system_gems ENV["GEM_HOME"] = gem_path ENV["GEM_PATH"] = gem_path end ENV["PATH"] = "#{bindir}:#{ENV["PATH"]}" ENV["RUBYOPT"] = "-r#{gem_path}/environment #{ENV["RUBYOPT"]}" end |
#source_index ⇒ Object
162 163 164 165 166 |
# File 'lib/bowline/bundler/bundle.rb', line 162 def source_index index = Gem::SourceIndex.from_gems_in(@specs_path) index.each { |n, spec| spec.loaded_from = @specs_path.join("#{spec.full_name}.gemspec") } index end |