Class: Bundler::Environment
- Inherits:
-
Object
- Object
- Bundler::Environment
- Defined in:
- lib/bundler/environment.rb
Instance Attribute Summary collapse
- #bindir ⇒ Object
-
#dependencies ⇒ Object
readonly
Returns the value of attribute dependencies.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
- #gem_path ⇒ Object
-
#rubygems ⇒ Object
Returns the value of attribute rubygems.
-
#system_gems ⇒ Object
Returns the value of attribute system_gems.
Class Method Summary collapse
Instance Method Summary collapse
- #add_priority_source(source) ⇒ Object
- #add_source(source) ⇒ Object
- #cache(options = {}) ⇒ Object
- #clear_sources ⇒ Object
-
#initialize(filename) ⇒ Environment
constructor
A new instance of Environment.
- #install(options = {}) ⇒ Object
- #list(options = {}) ⇒ Object
- #list_outdated(options = {}) ⇒ Object
- #prune(options = {}) ⇒ Object
- #require_env(env = nil) ⇒ Object
- #root ⇒ Object
- #setup_environment ⇒ Object
- #sources ⇒ Object
Constructor Details
#initialize(filename) ⇒ Environment
Returns a new instance of Environment.
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/bundler/environment.rb', line 35 def initialize(filename) @filename = filename @default_sources = default_sources @sources = [] @priority_sources = [] @dependencies = [] @rubygems = true @system_gems = true # Evaluate the Gemfile Dsl.evaluate(self, filename) end |
Instance Attribute Details
#bindir ⇒ Object
146 147 148 |
# File 'lib/bundler/environment.rb', line 146 def bindir @bindir ||= root.join("bin") end |
#dependencies ⇒ Object (readonly)
Returns the value of attribute dependencies.
9 10 11 |
# File 'lib/bundler/environment.rb', line 9 def dependencies @dependencies end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
9 10 11 |
# File 'lib/bundler/environment.rb', line 9 def filename @filename end |
#gem_path ⇒ Object
142 143 144 |
# File 'lib/bundler/environment.rb', line 142 def gem_path @gem_path ||= root.join("vendor", "gems") end |
#rubygems ⇒ Object
Returns the value of attribute rubygems.
10 11 12 |
# File 'lib/bundler/environment.rb', line 10 def rubygems @rubygems end |
#system_gems ⇒ Object
Returns the value of attribute system_gems.
10 11 12 |
# File 'lib/bundler/environment.rb', line 10 def system_gems @system_gems end |
Class Method Details
.default_manifest_file ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/bundler/environment.rb', line 23 def self.default_manifest_file 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(file = nil) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/bundler/environment.rb', line 13 def self.load(file = nil) gemfile = Pathname.new(file || default_manifest_file). unless gemfile.file? raise ManifestFileNotFound, "Manifest file not found: #{gemfile.to_s.inspect}" end new(gemfile) end |
Instance Method Details
#add_priority_source(source) ⇒ Object
158 159 160 |
# File 'lib/bundler/environment.rb', line 158 def add_priority_source(source) @priority_sources << source end |
#add_source(source) ⇒ Object
154 155 156 |
# File 'lib/bundler/environment.rb', line 154 def add_source(source) @sources << source end |
#cache(options = {}) ⇒ Object
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 |
# File 'lib/bundler/environment.rb', line 72 def cache( = {}) gemfile = [:cache] if File.extname(gemfile) == ".gem" if !File.exist?(gemfile) raise InvalidCacheArgument, "'#{gemfile}' does not exist." end repository.cache(gemfile) elsif File.directory?(gemfile) || gemfile.include?('/') if !File.directory?(gemfile) raise InvalidCacheArgument, "'#{gemfile}' does not exist." end gemfiles = Dir["#{gemfile}/*.gem"] if gemfiles.empty? raise InvalidCacheArgument, "'#{gemfile}' contains no gemfiles" end repository.cache(*gemfiles) else local = Gem::SourceIndex.from_installed_gems.find_name(gemfile).last if !local raise InvalidCacheArgument, "w0t? '#{gemfile}' means nothing to me." end gemfile = Pathname.new(local.loaded_from) gemfile = gemfile.dirname.join('..', 'cache', "#{local.full_name}.gem"). repository.cache(gemfile) end end |
#clear_sources ⇒ Object
162 163 164 165 |
# File 'lib/bundler/environment.rb', line 162 def clear_sources @sources.clear @default_sources.clear end |
#install(options = {}) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/bundler/environment.rb', line 48 def install( = {}) if only_envs = [:only] dependencies.reject! { |d| !only_envs.any? {|env| d.in?(env) } } end no_bundle = dependencies.map do |dep| dep.source == SystemGemSource.instance && dep.name end.compact update = [:update] cached = [:cached] repository.install(dependencies, sources, :rubygems => rubygems, :system_gems => system_gems, :manifest => filename, :update => [:update], :cached => [:cached], :build_options => [:build_options], :no_bundle => no_bundle ) Bundler.logger.info "Done." end |
#list(options = {}) ⇒ Object
106 107 108 109 110 111 |
# File 'lib/bundler/environment.rb', line 106 def list( = {}) Bundler.logger.info "Currently bundled gems:" repository.gems.each do |spec| Bundler.logger.info " * #{spec.name} (#{spec.version})" end end |
#list_outdated(options = {}) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/bundler/environment.rb', line 113 def list_outdated(={}) outdated_gems = repository.outdated_gems 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 |
#prune(options = {}) ⇒ Object
102 103 104 |
# File 'lib/bundler/environment.rb', line 102 def prune( = {}) repository.prune(gem_dependencies, sources) end |
#require_env(env = nil) ⇒ Object
134 135 136 |
# File 'lib/bundler/environment.rb', line 134 def require_env(env = nil) dependencies.each { |d| d.require_env(env) } end |
#root ⇒ Object
138 139 140 |
# File 'lib/bundler/environment.rb', line 138 def root filename.parent end |
#setup_environment ⇒ Object
125 126 127 128 129 130 131 132 |
# File 'lib/bundler/environment.rb', line 125 def setup_environment unless 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 |
#sources ⇒ Object
150 151 152 |
# File 'lib/bundler/environment.rb', line 150 def sources @priority_sources + @sources + @default_sources end |