Sha256: 0c51e1d0027a5bd6a7a0915fa14ef0f423d565a152b834b7d1d03da7f9adb7e6

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 KB

Contents

require_relative 'base_decorator'
require_relative 'version_decorator'
require_relative 'latest_pact_decorator'
require_relative 'representable_pact'

module PactBroker

  module Api

    module Decorators

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

        collection :pacts, decorator_scope: true, :class => PactBroker::Models::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 :pacts do | options |
          represented.collect{ | pact | {:href => latest_pact_url(options[:base_url], pact), :title => "Latest pact between #{pact.consumer.name} and #{pact.provider.name}" } }
        end

      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pact_broker-0.0.10 lib/pact_broker/api/decorators/pact_collection_decorator.rb