Module: PDK::Util::Bundler
- Defined in:
- lib/pdk/util/bundler.rb
Defined Under Namespace
Classes: BundleHelper
Class Method Summary collapse
- .already_bundled?(gemfile) ⇒ Boolean
- .ensure_binstubs!(*gems) ⇒ Object
- .ensure_bundle! ⇒ Object
- .mark_as_bundled!(gemfile) ⇒ Object
Class Method Details
.already_bundled?(gemfile) ⇒ Boolean
51 52 53 |
# File 'lib/pdk/util/bundler.rb', line 51 def self.already_bundled?(gemfile) !(@bundled ||= {})[gemfile].nil? end |
.ensure_binstubs!(*gems) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/pdk/util/bundler.rb', line 59 def self.ensure_binstubs!(*gems) bundle = BundleHelper.new unless bundle.binstubs!(gems) # rubocop:disable Style/GuardClause raise PDK::CLI::FatalError, _('Unable to install requested binstubs.') end end |
.ensure_bundle! ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/pdk/util/bundler.rb', line 11 def self.ensure_bundle! bundle = BundleHelper.new if already_bundled?(bundle.gemfile) PDK.logger.debug(_('Bundle has already been installed, skipping run')) return end unless bundle.gemfile? PDK.logger.debug(_("No Gemfile found in '%{cwd}', skipping bundler management") % { cwd: Dir.pwd }) return end unless bundle.locked? if PDK::Util.package_install? # In packaged installs, try to use vendored Gemfile.lock as a starting point. # The 'bundle install' below will pick up any new dependencies. vendored_gemfile_lock = File.join(PDK::Util.package_cachedir, 'Gemfile.lock') if File.exist?(vendored_gemfile_lock) PDK.logger.debug(_("No Gemfile.lock found in module, using vendored Gemfile.lock from '%{source}'") % { source: vendored_gemfile_lock }) FileUtils.cp(vendored_gemfile_lock, File.join(PDK::Util.module_root, 'Gemfile.lock')) end else # In non-packaged installs, just let bundler resolve deps as normal. unless bundle.lock! raise PDK::CLI::FatalError, _('Unable to resolve Gemfile dependencies.') end end end unless bundle.installed? unless bundle.install! raise PDK::CLI::FatalError, _('Unable to install missing Gemfile dependencies.') end end mark_as_bundled!(bundle.gemfile) end |
.mark_as_bundled!(gemfile) ⇒ Object
55 56 57 |
# File 'lib/pdk/util/bundler.rb', line 55 def self.mark_as_bundled!(gemfile) (@bundled ||= {})[gemfile] = true end |