Sha256: f27bd8d879bde1136d5b876b0eee0ee62eb379a93534c5c8c533a6a2a4bae037

Contents?: true

Size: 1.6 KB

Versions: 22

Compression:

Stored size: 1.6 KB

Contents

module Terraspace
  # Named Bundle vs Bundler to avoid having to fully qualify ::Bundler
  module Bundle
    # Looks like for zeitwerk module autovivification to work `bundle exec` must be called.
    # This allows zeitwork module autovivification to work even if the user has not called terraspace with `bundle exec terraspace`.
    # Bundler.setup is essentially the same as `bundle exec`
    # Reference: https://www.justinweiss.com/articles/what-are-the-differences-between-irb/
    #
    def setup
      return unless gemfile?
      Kernel.require "bundler/setup"
      Bundler.setup # Same as Bundler.setup(:default)
    rescue LoadError => e
      handle_error(e)
    end

    def require
      return unless gemfile?
      Kernel.require "bundler/setup"
      Bundler.require(*bundler_groups)
    rescue LoadError => e
      handle_error(e)
    end

    def handle_error(e)
      puts e.message
      return if e.message.include?("already activated")
      puts <<~EOL.color(:yellow)
        WARNING: Unable to require "bundler/setup"
        There may be something funny with your ruby and bundler setup.
        You can try upgrading bundler and rubygems:

            gem update --system
            gem install bundler

        Here are some links that may be helpful:

        * https://bundler.io/blog/2019/01/03/announcing-bundler-2.html

        Also, running bundle exec in front of your command may remove this message.
      EOL
    end

    def gemfile?
      ENV['BUNDLE_GEMFILE'] || File.exist?("Gemfile")
    end

    def bundler_groups
      [:default, Terraspace.env.to_sym]
    end

    extend self
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
terraspace-0.5.1 lib/terraspace/bundle.rb
terraspace-0.5.0 lib/terraspace/bundle.rb
terraspace-0.4.4 lib/terraspace/bundle.rb
terraspace-0.4.3 lib/terraspace/bundle.rb
terraspace-0.4.2 lib/terraspace/bundle.rb
terraspace-0.4.1 lib/terraspace/bundle.rb
terraspace-0.4.0 lib/terraspace/bundle.rb
terraspace-0.3.6 lib/terraspace/bundle.rb
terraspace-0.3.5 lib/terraspace/bundle.rb
terraspace-0.3.4 lib/terraspace/bundle.rb
terraspace-0.3.3 lib/terraspace/bundle.rb
terraspace-0.3.2 lib/terraspace/bundle.rb
terraspace-0.3.1 lib/terraspace/bundle.rb
terraspace-0.3.0 lib/terraspace/bundle.rb
terraspace-0.2.4 lib/terraspace/bundle.rb
terraspace-0.2.3 lib/terraspace/bundle.rb
terraspace-0.2.2 lib/terraspace/bundle.rb
terraspace-0.2.1 lib/terraspace/bundle.rb
terraspace-0.2.0 lib/terraspace/bundle.rb
terraspace-0.1.2 lib/terraspace/bundle.rb