Sha256: be821a6b29e80c9b8e4cdf02bf33fab2494e5fc957da5f1587180b8b404696e6

Contents?: true

Size: 1.51 KB

Versions: 17

Compression:

Stored size: 1.51 KB

Contents

# frozen_string_literal: true

require "versionaire"

module Gemsmith
  module Gem
    # A Gem::Specification with additional enhancements.
    class Specification
      def self.specification
        ::Gem::Specification
      end

      def self.default_gem_host
        ::Gem::DEFAULT_HOST
      end

      def self.find name, version
        specification.find_by_name name, version
      end

      def self.find_all name, requirement: Gem::Requirement.new.to_s
        specification.find_all_by_name name, requirement
      end

      attr_reader :version

      def initialize file_path
        @file_path = file_path
        @spec = self.class.specification.load file_path
        validate
        @version = Versionaire::Version @spec.version.to_s
      end

      def name
        spec.name
      end

      def path
        spec.full_gem_path
      end

      def homepage_url
        String spec.homepage
      end

      def allowed_push_key
        spec.metadata.fetch("allowed_push_key") { "rubygems_api_key" }
      end

      def allowed_push_host
        spec.metadata.fetch("allowed_push_host") { self.class.default_gem_host }
      end

      def package_file_name
        "#{name}-#{version}.gem"
      end

      def package_path
        File.join "pkg", package_file_name
      end

      private

      attr_reader :file_path, :spec

      def validate
        return if spec.is_a? self.class.specification

        fail Errors::Specification, %(Unknown gem specification: "#{file_path}".)
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
gemsmith-14.2.0 lib/gemsmith/gem/specification.rb
gemsmith-14.1.3 lib/gemsmith/gem/specification.rb
gemsmith-14.1.2 lib/gemsmith/gem/specification.rb
gemsmith-14.1.1 lib/gemsmith/gem/specification.rb
gemsmith-14.1.0 lib/gemsmith/gem/specification.rb
gemsmith-14.0.2 lib/gemsmith/gem/specification.rb
gemsmith-14.0.1 lib/gemsmith/gem/specification.rb
gemsmith-14.0.0 lib/gemsmith/gem/specification.rb
gemsmith-13.8.0 lib/gemsmith/gem/specification.rb
gemsmith-13.7.2 lib/gemsmith/gem/specification.rb
gemsmith-13.7.1 lib/gemsmith/gem/specification.rb
gemsmith-13.7.0 lib/gemsmith/gem/specification.rb
gemsmith-13.6.0 lib/gemsmith/gem/specification.rb
gemsmith-13.5.0 lib/gemsmith/gem/specification.rb
gemsmith-13.4.0 lib/gemsmith/gem/specification.rb
gemsmith-13.3.0 lib/gemsmith/gem/specification.rb
gemsmith-13.2.0 lib/gemsmith/gem/specification.rb