Module: Terraspace::Bundle
Overview
Named Bundle vs Bundler to avoid having to fully qualify ::Bundler
Instance Method Summary collapse
- #bundler_groups ⇒ Object
- #check_shim! ⇒ Object
- #gemfile? ⇒ Boolean
-
#handle_already_activated_error(e) ⇒ Object
When there are gem dependency issues, requiring zeitwerk with this debugging code begin require "zeitwerk" rescue LoadError => e puts "#ee.class: #ee.message" exit 1 end.
- #handle_error(e) ⇒ Object
- #require ⇒ Object
-
#setup ⇒ Object
Looks like for zeitwerk module autovivification to work
bundle execmust be called. - #terraspace_project? ⇒ Boolean
Instance Method Details
#bundler_groups ⇒ Object
54 55 56 |
# File 'lib/terraspace/bundle.rb', line 54 def bundler_groups [:default, Terraspace.env.to_sym] end |
#check_shim! ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/terraspace/bundle.rb', line 97 def check_shim! return unless File.exist?("Gemfile") $stderr.puts " Looks like there are issues trying to resolve gem dependencies.\n\n To resolve this, you can generate a shim:\n\n terraspace new shim\n\n You only have to do this one time.\n\n More info: https://terraspace.cloud/docs/install/shim/\n EOL\nend\n" |
#gemfile? ⇒ Boolean
50 51 52 |
# File 'lib/terraspace/bundle.rb', line 50 def gemfile? ENV['BUNDLE_GEMFILE'] || File.exist?("Gemfile") end |
#handle_already_activated_error(e) ⇒ Object
When there are gem dependency issues, requiring zeitwerk with this debugging code begin require "zeitwerk" rescue LoadError => e puts "#Terraspace::Bundle.ee.class: #Terraspace::Bundle.ee.message" exit 1 end
Produces:
You have already activated faraday 1.8.0, but your Gemfile requires faraday 1.7.2. Prepending `bundle exec` to your command may solve this.
LoadError: cannot load such file -- zeitwerk
Sadly, the captured exception only contains this info:
LoadError: cannot load such file -- zeitwerk
The useful "already activated" info that shows gem dependencies issues. Example:
You have already activated faraday 1.8.0, but your Gemfile requires faraday 1.7.2. Prepending `bundle exec` to your command may solve this.
Is printed to stdout earlier and before exception.
So making an assumption that a zeitwerk LoadError is due to gem dependencies issue. It's not ideal, but think this is ok.
Note: Not checking shim upon install because it wont be a good user experience to check for a shim unless this error actually occurs.
Only been able to reproduce this error for a gem install with: alpine The standalone install already has a shim wrapper.
90 91 92 93 94 95 |
# File 'lib/terraspace/bundle.rb', line 90 def handle_already_activated_error(e) # color is not yet available puts "ERROR: #{e.class}: #{e.message}" if ENV['TS_DEBUG_ALREADY_ACTIVATED'] check_shim! exit 1 end |
#handle_error(e) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/terraspace/bundle.rb', line 31 def handle_error(e) puts e. return if e..include?("already activated") puts " WARNING: Unable to require \"bundler/setup\"\n There may be something funny with your ruby and bundler setup.\n You can try upgrading bundler and rubygems:\n\n gem update --system\n gem install bundler\n\n Here are some links that may be helpful:\n\n * https://bundler.io/blog/2019/01/03/announcing-bundler-2.html\n\n Also, running bundle exec in front of your command may remove this message.\n EOL\nend\n".color(:yellow) |
#require ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/terraspace/bundle.rb', line 18 def require return unless gemfile? return unless terraspace_project? Kernel.require "bundler/setup" Bundler.require(*bundler_groups) rescue LoadError => e handle_error(e) end |
#setup ⇒ Object
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/
9 10 11 12 13 14 15 16 |
# File 'lib/terraspace/bundle.rb', line 9 def setup return unless gemfile? return unless terraspace_project? Kernel.require "bundler/setup" Bundler.setup # Same as Bundler.setup(:default) rescue LoadError => e handle_error(e) end |
#terraspace_project? ⇒ Boolean
27 28 29 |
# File 'lib/terraspace/bundle.rb', line 27 def terraspace_project? File.exist?("config/app.rb") end |