Sha256: 2fdaf13679505c314f605fdeb2f91dc9632dd657ad88b980cf305917b1b2ec0b

Contents?: true

Size: 870 Bytes

Versions: 1

Compression:

Stored size: 870 Bytes

Contents

require "gems"

module Codestatus
  module PackageResolvers
    class RubygemsResolver < Base
      private

      def found?
        gem_info
      end

      def urls
        [
          source_code_uri,
          homepage_uri,
          bug_tracker_uri,
        ].compact
      end

      def homepage_uri
        gem_info&.dig('homepage_uri')
      end

      def source_code_uri
        gem_info&.dig('source_code_uri')
      end

      def bug_tracker_uri
        gem_info&.dig('bug_tracker_uri')
      end

      def gem_info
        @info ||= begin
                    Gems.info(package)
                  rescue JSON::ParserError
                    # When the package is not found on rubygems,
                    # Gems does try to parse html as json and raise JSON::ParserError :sob:
                    nil
                  end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
codestatus-0.1.3 lib/codestatus/package_resolvers/rubygems_resolver.rb