Module: PDK::Util::Bundler

Defined in:
lib/pdk/util/bundler.rb

Defined Under Namespace

Classes: BundleHelper

Class Method Summary collapse

Class Method Details

.already_bundled?(gemfile, gem_overrides) ⇒ Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/pdk/util/bundler.rb', line 64

def self.already_bundled?(gemfile, gem_overrides)
  !(@bundled ||= {})[bundle_cache_key(gemfile, gem_overrides)].nil?
end

.ensure_binstubs!(*gems) ⇒ Object



58
59
60
61
62
# File 'lib/pdk/util/bundler.rb', line 58

def self.ensure_binstubs!(*gems)
  bundle = BundleHelper.new

  bundle.binstubs!(gems)
end

.ensure_bundle!(gem_overrides = nil) ⇒ Object



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
50
51
52
53
54
55
56
# File 'lib/pdk/util/bundler.rb', line 12

def self.ensure_bundle!(gem_overrides = nil)
  bundle = BundleHelper.new

  # This will default ensure_bundle! to re-resolving everything to latest
  gem_overrides ||= { puppet: nil, hiera: nil, facter: nil }

  if already_bundled?(bundle.gemfile, gem_overrides)
    PDK.logger.debug(_('Bundler managed gems already up to date.'))
    return
  end

  unless bundle.gemfile?
    PDK.logger.debug(_("No Gemfile found in '%{cwd}'. Skipping bundler management.") % { cwd: Dir.pwd })
    return
  end

  unless bundle.locked?
    # Generate initial default Gemfile.lock, either from package cache or
    # by invoking `bundle lock`
    bundle.lock!
  end

  # Check if all dependencies will be available once we update the lockfile.
  begin
    original_lockfile = bundle.gemfile_lock
    temp_lockfile = "#{original_lockfile}.tmp"

    FileUtils.mv(original_lockfile, temp_lockfile)

    all_deps_available = bundle.installed?(gem_overrides)
  ensure
    FileUtils.mv(temp_lockfile, original_lockfile, force: true)
  end

  bundle.update_lock!(with: gem_overrides, local: all_deps_available)

  # If there are missing dependencies after updating the lockfile, let `bundle install`
  # go out and get them. If the specified puppet gem version points to a remote location
  # or local filepath, then run bundle install as well.
  if !bundle.installed? || (gem_overrides[:puppet] && gem_overrides[:puppet].start_with?('file://', 'git://', 'https://'))
    bundle.install!(gem_overrides)
  end

  mark_as_bundled!(bundle.gemfile, gem_overrides)
end

.mark_as_bundled!(gemfile, gem_overrides) ⇒ Object



68
69
70
# File 'lib/pdk/util/bundler.rb', line 68

def self.mark_as_bundled!(gemfile, gem_overrides)
  (@bundled ||= {})[bundle_cache_key(gemfile, gem_overrides)] = true
end