File: bundle

package info (click to toggle)
ruby-byebug 11.1.3-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,252 kB
  • sloc: ruby: 8,835; ansic: 1,662; sh: 6; makefile: 4
file content (42 lines) | stat: -rwxr-xr-x 721 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
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
#!/usr/bin/env ruby
# frozen_string_literal: true

require "rubygems"

m = Module.new do
  extend self

  def gemfile
    File.expand_path("../Gemfile", __dir__)
  end

  def lockfile
    "#{gemfile}.lock"
  end

  def lockfile_version
    return unless File.file?(lockfile)

    lockfile_contents = File.read(lockfile)

    regexp = /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/

    regexp.match(lockfile_contents)[1]
  end

  def bundler_version
    @bundler_version ||= lockfile_version
  end

  def load_bundler!
    ENV["BUNDLE_GEMFILE"] ||= gemfile

    activate_bundler(bundler_version)
  end

  def activate_bundler(bundler_version)
    gem "bundler", bundler_version
  end
end

m.load_bundler!