Sha256: e3aa1f25aca857d6c625fce03b7fb37f2f70d1358d5f99ef12e59baa03a0389f

Contents?: true

Size: 1.58 KB

Versions: 36

Compression:

Stored size: 1.58 KB

Contents

require "pact_broker/api/resources/base_resource"
require "pact_broker/configuration"
require "pact_broker/api/decorators/extended_pact_decorator"
require "pact_broker/pacts/metadata"

module PactBroker
  module Api
    module Resources
      class LatestPact < BaseResource
        def content_types_provided
          [
            ["application/hal+json", :to_json],
            ["application/json", :to_json],
            ["text/html", :to_html],
            ["application/vnd.pactbrokerextended.v1+json", :to_extended_json]
          ]
        end

        def allowed_methods
          ["GET", "OPTIONS"]
        end

        def resource_exists?
          !!pact
        end

        def policy_name
          :'pacts::pact'
        end

        def to_json
          response.headers["X-Pact-Consumer-Version"] = pact.consumer_version_number
          decorator_class(:pact_decorator).new(pact).to_json(decorator_options(metadata: metadata))
        end

        def to_extended_json
          decorator_class(:extended_pact_decorator).new(pact).to_json(decorator_options(metadata: metadata))
        end

        def to_html
          PactBroker.configuration.html_pact_renderer.call(
            pact, {
              base_url: ui_base_url,
              badge_url: "#{resource_url}/badge.svg"
          })
        end

        def pact
          @pact ||= pact_service.find_latest_pact(identifier_from_path)
        end

        def metadata
          @metadata ||= encode_metadata(PactBroker::Pacts::Metadata.build_metadata_for_latest_pact(pact, identifier_from_path))
        end
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
pact_broker-2.106.0 lib/pact_broker/api/resources/latest_pact.rb
pact_broker-2.105.0 lib/pact_broker/api/resources/latest_pact.rb
pact_broker-2.104.0 lib/pact_broker/api/resources/latest_pact.rb
pact_broker-2.103.0 lib/pact_broker/api/resources/latest_pact.rb
pact_broker-2.102.2 lib/pact_broker/api/resources/latest_pact.rb
pact_broker-2.102.1 lib/pact_broker/api/resources/latest_pact.rb
pact_broker-2.102.0 lib/pact_broker/api/resources/latest_pact.rb
pact_broker-2.101.0 lib/pact_broker/api/resources/latest_pact.rb
pact_broker-2.100.0 lib/pact_broker/api/resources/latest_pact.rb
pact_broker-2.99.0 lib/pact_broker/api/resources/latest_pact.rb
pact_broker-2.98.0 lib/pact_broker/api/resources/latest_pact.rb
pact_broker-2.97.0 lib/pact_broker/api/resources/latest_pact.rb
pact_broker-2.96.0 lib/pact_broker/api/resources/latest_pact.rb
pact_broker-2.95.1 lib/pact_broker/api/resources/latest_pact.rb
pact_broker-2.95.0 lib/pact_broker/api/resources/latest_pact.rb
pact_broker-2.94.0 lib/pact_broker/api/resources/latest_pact.rb
pact_broker-2.93.4 lib/pact_broker/api/resources/latest_pact.rb
pact_broker-2.93.3 lib/pact_broker/api/resources/latest_pact.rb
pact_broker-2.93.2 lib/pact_broker/api/resources/latest_pact.rb
pact_broker-2.93.1 lib/pact_broker/api/resources/latest_pact.rb