Sha256: cb155974d96f812d4c65260713974670e490b95a4d1c07095b5c4e80789a7036

Contents?: true

Size: 1.76 KB

Versions: 45

Compression:

Stored size: 1.76 KB

Contents

require_relative "base_decorator"
require_relative "embedded_version_decorator"
require_relative "latest_pact_decorator"
require_relative "representable_pact"
require "pact_broker/domain/pact"

module PactBroker
  module Api
    module Decorators
      class PactCollectionDecorator < BaseDecorator
        include Roar::JSON::HAL
        include PactBroker::Api::PactBrokerUrls

        collection :pacts, exec_context: :decorator, :class => PactBroker::Domain::Pact, :extend => PactBroker::Api::Decorators::LatestPactDecorator

        def pacts
          represented.collect{ | pact | create_representable_pact(pact) }
        end

        def create_representable_pact pact
          PactBroker::Api::Decorators::RepresentablePact.new(pact)
        end

        link :self do | options |
          latest_pacts_url(options[:base_url])
        end

        # This is the LATEST pact URL
        links :'pb:pacts' do | options |
          represented.collect do | pact |
            {
              :href => latest_pact_url(options[:base_url], pact),
              :title => "Latest pact between #{pact.consumer.name} and #{pact.provider.name}",
            }
          end
        end

        # This is the LATEST pact URL
        links :pacts do | options |
          represented.collect do | pact |
            {
              :href => latest_pact_url(options[:base_url], pact),
              :title => "Latest pact between #{pact.consumer.name} and #{pact.provider.name}",
              :name => "DEPRECATED - please use the pb:pacts relation"
            }
          end
        end

        curies do | options |
          [{
            name: :pb,
            href: options[:base_url] + "/doc/{rel}?context=pacts",
            templated: true
          }]
        end
      end
    end
  end
end

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
pact_broker-2.113.0 lib/pact_broker/api/decorators/pact_collection_decorator.rb
pact_broker-2.112.0 lib/pact_broker/api/decorators/pact_collection_decorator.rb
pact_broker-2.111.0 lib/pact_broker/api/decorators/pact_collection_decorator.rb
pact_broker-2.109.1 lib/pact_broker/api/decorators/pact_collection_decorator.rb
pact_broker-2.109.0 lib/pact_broker/api/decorators/pact_collection_decorator.rb
pact_broker-2.108.0 lib/pact_broker/api/decorators/pact_collection_decorator.rb
pact_broker-2.107.1 lib/pact_broker/api/decorators/pact_collection_decorator.rb
pact_broker-2.107.0 lib/pact_broker/api/decorators/pact_collection_decorator.rb
pact_broker-2.107.0.beta.1 lib/pact_broker/api/decorators/pact_collection_decorator.rb
pact_broker-2.106.0 lib/pact_broker/api/decorators/pact_collection_decorator.rb
pact_broker-2.105.0 lib/pact_broker/api/decorators/pact_collection_decorator.rb
pact_broker-2.104.0 lib/pact_broker/api/decorators/pact_collection_decorator.rb
pact_broker-2.103.0 lib/pact_broker/api/decorators/pact_collection_decorator.rb
pact_broker-2.102.2 lib/pact_broker/api/decorators/pact_collection_decorator.rb
pact_broker-2.102.1 lib/pact_broker/api/decorators/pact_collection_decorator.rb
pact_broker-2.102.0 lib/pact_broker/api/decorators/pact_collection_decorator.rb
pact_broker-2.101.0 lib/pact_broker/api/decorators/pact_collection_decorator.rb
pact_broker-2.100.0 lib/pact_broker/api/decorators/pact_collection_decorator.rb
pact_broker-2.99.0 lib/pact_broker/api/decorators/pact_collection_decorator.rb
pact_broker-2.98.0 lib/pact_broker/api/decorators/pact_collection_decorator.rb