diff options
-rw-r--r-- | lib/bundler.rb | 4 | ||||
-rw-r--r-- | lib/bundler/environment.rb | 46 | ||||
-rw-r--r-- | lib/bundler/installer.rb | 24 | ||||
-rw-r--r-- | lib/bundler/runtime.rb | 25 | ||||
-rw-r--r-- | spec/other/major_deprecation_spec.rb | 8 |
5 files changed, 54 insertions, 53 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb index 98f81234..b940dc06 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -26,7 +26,6 @@ module Bundler autoload :Dsl, "bundler/dsl" autoload :EndpointSpecification, "bundler/endpoint_specification" autoload :Env, "bundler/env" - autoload :Environment, "bundler/environment" autoload :Fetcher, "bundler/fetcher" autoload :GemHelper, "bundler/gem_helper" autoload :GemHelpers, "bundler/gem_helpers" @@ -112,7 +111,8 @@ module Bundler end def environment - Bundler::Environment.new(root, definition) + SharedHelpers.major_deprecation "Bundler.environment has been removed in favor of Bundler.load" + load end # Returns an instance of Bundler::Definition for given Gemfile and lockfile diff --git a/lib/bundler/environment.rb b/lib/bundler/environment.rb deleted file mode 100644 index fedc6b29..00000000 --- a/lib/bundler/environment.rb +++ /dev/null @@ -1,46 +0,0 @@ -# frozen_string_literal: true -module Bundler - class Environment - attr_reader :root - - def initialize(root, definition) - @root = root - @definition = definition - - env_file = Bundler.app_config_path.join("environment.rb") - env_file.rmtree if env_file.exist? - end - - def inspect - @definition.to_lock.inspect - end - - def requested_specs - @definition.requested_specs - end - - def specs - @definition.specs - end - - def dependencies - @definition.dependencies - end - - def current_dependencies - @definition.current_dependencies - end - - def requires - @definition.requires - end - - def lock(opts = {}) - @definition.lock(Bundler.default_lockfile, opts[:preserve_unknown_sections]) - end - - def update(*gems) - # Nothing - end - end -end diff --git a/lib/bundler/installer.rb b/lib/bundler/installer.rb index 3d51505b..c7ce68d2 100644 --- a/lib/bundler/installer.rb +++ b/lib/bundler/installer.rb @@ -7,7 +7,7 @@ require "bundler/installer/standalone" require "bundler/installer/gem_installer" module Bundler - class Installer < Environment + class Installer class << self attr_accessor :post_install_messages, :ambiguous_gems @@ -23,6 +23,11 @@ module Bundler installer end + def initialize(root, definition) + @root = root + @definition = definition + end + # Runs the install procedures for a specific Gemfile. # # Firstly, this method will check to see if Bundler.bundle_path exists @@ -56,12 +61,13 @@ module Bundler # Finally: TODO add documentation for how the standalone process works. def run(options) create_bundle_path + remove_0_9_environment_rb if Bundler.settings[:frozen] @definition.ensure_equivalent_gemfile_and_lockfile(options[:deployment]) end - if dependencies.empty? + if @definition.dependencies.empty? Bundler.ui.warn "The Gemfile specifies no dependencies" lock return @@ -160,7 +166,7 @@ module Bundler def ensure_specs_are_compatible! system_ruby = Bundler::RubyVersion.system rubygems_version = Gem::Version.create(Gem::VERSION) - specs.each do |spec| + @definition.specs.each do |spec| if required_ruby_version = spec.required_ruby_version unless required_ruby_version.satisfied_by?(system_ruby.gem_version) raise InstallError, "#{spec.full_name} requires ruby version #{required_ruby_version}, " \ @@ -187,7 +193,7 @@ module Bundler end def install_in_parallel(size, standalone, force = false) - ParallelInstaller.call(self, specs, size, standalone, force) + ParallelInstaller.call(self, @definition.specs, size, standalone, force) end def create_bundle_path @@ -213,5 +219,15 @@ module Bundler return if local options["local"] ? @definition.resolve_with_cache! : @definition.resolve_remotely! end + + def remove_0_9_environment_rb + SharedHelpers.filesystem_access(Bundler.app_config_path.join("environment.rb")) do |env_file| + env_file.rmtree if env_file.exist? + end + end + + def lock(opts = {}) + @definition.lock(Bundler.default_lockfile, opts[:preserve_unknown_sections]) + end end end diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb index 3a86fe92..fb2c76bc 100644 --- a/lib/bundler/runtime.rb +++ b/lib/bundler/runtime.rb @@ -2,9 +2,14 @@ require "digest/sha1" module Bundler - class Runtime < Environment + class Runtime include SharedHelpers + def initialize(root, definition) + @root = root + @definition = definition + end + def setup(*groups) groups.map!(&:to_sym) @@ -107,6 +112,24 @@ module Bundler end end + def self.definition_method(meth) + define_method(meth) do + raise ArgumentError, "no definition when calling Runtime##{meth}" unless @definition + @definition.send(meth) + end + end + private_class_method :definition_method + + definition_method :requested_specs + definition_method :specs + definition_method :dependencies + definition_method :current_dependencies + definition_method :requires + + def lock(opts = {}) + @definition.lock(Bundler.default_lockfile, opts[:preserve_unknown_sections]) + end + alias_method :gems, :specs def cache(custom_path = nil) diff --git a/spec/other/major_deprecation_spec.rb b/spec/other/major_deprecation_spec.rb index a28a7e2e..c8a26332 100644 --- a/spec/other/major_deprecation_spec.rb +++ b/spec/other/major_deprecation_spec.rb @@ -31,6 +31,14 @@ describe "major deprecations" do end end + describe ".environment" do + it "is deprecated in favor of .load" do + source = "Bundler.environment" + bundle "exec ruby -e #{source.dump}" + expect(warnings).to have_major_deprecation "Bundler.environment has been removed in favor of Bundler.load" + end + end + shared_examples_for "environmental deprecations" do |trigger| describe "ruby version", :ruby => "< 2.0" do it "requires a newer ruby version" do |