Module: StillActive::BundlerHelper

Extended by:
BundlerHelper
Included in:
BundlerHelper
Defined in:
lib/helpers/bundler_helper.rb

Instance Method Summary collapse

Instance Method Details

#gemfile_dependencies(gemfile_path: StillActive.config.gemfile_path) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/helpers/bundler_helper.rb', line 7

def gemfile_dependencies(gemfile_path: StillActive.config.gemfile_path)
  absolute_gemfile = File.expand_path(gemfile_path)
  ::Bundler::SharedHelpers.set_env("BUNDLE_GEMFILE", absolute_gemfile)
  gemfile_gems = ::Bundler.definition.dependencies.map(&:name)
  locked_gems = ::Bundler.definition.locked_gems
  if locked_gems.nil?
    raise MissingLockfileError,
      "no lockfile next to #{absolute_gemfile} — run `bundle lock` (or `bundle install`) first"
  end

  locked_gems
    .specs
    .select { |spec| gemfile_gems.include?(spec.name) }
    .uniq(&:name)
    .map do |spec|
      {
        name: spec.name,
        version: spec.version.version,
        source_type: detect_source_type(spec),
        source_uri: detect_source_uri(spec),
      }
    end
end