Sha256: 37c2e09c960a5e197522404dd9d8b5bb1384d8db82dfc605ccfe3217cdcc477f

Contents?: true

Size: 1.66 KB

Versions: 9

Compression:

Stored size: 1.66 KB

Contents

# frozen_string_literal: true

require "bundler/match_platform"

# Bundler normally raises a "GemNotFound" error when a specification
# can't be materialized which halts bundler dependency enumeration.

# This monkey patch instead creates MissingSpecification objects to
# identify missing specs without raising errors and halting enumeration.
# It was the most minimal-touch solution I could think of that should reliably
# work across many bundler versions

module Licensed
  module Bundler
    class MissingSpecification < Gem::BasicSpecification
      include ::Bundler::MatchPlatform

      attr_reader :name, :version, :platform, :source
      def initialize(name:, version:, platform:, source:)
        @name = name
        @version = version
        @platform = platform
        @source = source
      end

      def dependencies
        []
      end

      def gem_dir; end
      def gems_dir
        Gem.dir
      end
      def summary; end
      def homepage; end

      def error
        "could not find #{name} (#{version}) in any sources"
      end
    end

    module LazySpecification
      def materialize_for_installation(*args)
        spec = super(*args)
        return spec unless spec.is_a?(LazySpecification)

        Licensed::Bundler::MissingSpecification.new(name: name, version: version, platform: platform, source: source)
      end

      def __materialize__(*args)
        spec = super(*args)
        return spec if spec

        Licensed::Bundler::MissingSpecification.new(name: name, version: version, platform: platform, source: source)
      end
    end
  end
end

module Bundler
  class LazySpecification
    prepend ::Licensed::Bundler::LazySpecification
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
licensed-4.0.2 lib/licensed/sources/bundler/missing_specification.rb
licensed-4.0.1 lib/licensed/sources/bundler/missing_specification.rb
licensed-4.0.0 lib/licensed/sources/bundler/missing_specification.rb
licensed-3.9.1 lib/licensed/sources/bundler/missing_specification.rb
licensed-3.9.0 lib/licensed/sources/bundler/missing_specification.rb
licensed-3.8.0 lib/licensed/sources/bundler/missing_specification.rb
licensed-3.7.5 lib/licensed/sources/bundler/missing_specification.rb
licensed-3.7.4 lib/licensed/sources/bundler/missing_specification.rb
licensed-3.7.3 lib/licensed/sources/bundler/missing_specification.rb