Sha256: 19a3fc0c8f464b84ab40a559973284d18f96e4679057afc906a4311bfc9ecb0a

Contents?: true

Size: 1.66 KB

Versions: 36

Compression:

Stored size: 1.66 KB

Contents

require "pact_broker/api/decorators/pact_decorator"

module PactBroker
  module Api
    module Decorators
      # Make a different content type for adding extra information for the UI, as
      # some pact parsing tools blow up when there are unexpected keys :|

      class ExtendedPactDecorator < PactDecorator
        class TagDecorator < BaseDecorator
          property :name
          property :latest, getter: ->(_) { true }

          link :self do | options |
            {
              title: "Tag",
              name: represented.name,
              href: tag_url(options[:base_url], represented)
            }
          end

          link "pb:latest-pact" do | opts |
            {
              name: "The latest pact with the tag #{represented.name}",
              href: latest_tagged_pact_url(represented.pact, represented.name, opts[:base_url])
            }
          end
        end

        property :content_hash, as: :contract
        collection :head_tags, exec_context: :decorator, as: :tags, embedded: true, extend: TagDecorator

        # TODO rather than remove the contract keys that we added in the super class,
        # it would be better to inherit from a shared super class
        def to_hash(options = {})
          keys_to_remove = represented.content_hash.keys
          super.each_with_object({}) do | (key, value), new_hash |
            new_hash[key] = value unless keys_to_remove.include?(key)
          end
        end

        def head_tags
          represented.head_tag_names.collect do | tag_name |
            OpenStruct.new(name: tag_name, pact: represented, version: represented.consumer_version)
          end
        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/decorators/extended_pact_decorator.rb
pact_broker-2.105.0 lib/pact_broker/api/decorators/extended_pact_decorator.rb
pact_broker-2.104.0 lib/pact_broker/api/decorators/extended_pact_decorator.rb
pact_broker-2.103.0 lib/pact_broker/api/decorators/extended_pact_decorator.rb
pact_broker-2.102.2 lib/pact_broker/api/decorators/extended_pact_decorator.rb
pact_broker-2.102.1 lib/pact_broker/api/decorators/extended_pact_decorator.rb
pact_broker-2.102.0 lib/pact_broker/api/decorators/extended_pact_decorator.rb
pact_broker-2.101.0 lib/pact_broker/api/decorators/extended_pact_decorator.rb
pact_broker-2.100.0 lib/pact_broker/api/decorators/extended_pact_decorator.rb
pact_broker-2.99.0 lib/pact_broker/api/decorators/extended_pact_decorator.rb
pact_broker-2.98.0 lib/pact_broker/api/decorators/extended_pact_decorator.rb
pact_broker-2.97.0 lib/pact_broker/api/decorators/extended_pact_decorator.rb
pact_broker-2.96.0 lib/pact_broker/api/decorators/extended_pact_decorator.rb
pact_broker-2.95.1 lib/pact_broker/api/decorators/extended_pact_decorator.rb
pact_broker-2.95.0 lib/pact_broker/api/decorators/extended_pact_decorator.rb
pact_broker-2.94.0 lib/pact_broker/api/decorators/extended_pact_decorator.rb
pact_broker-2.93.4 lib/pact_broker/api/decorators/extended_pact_decorator.rb
pact_broker-2.93.3 lib/pact_broker/api/decorators/extended_pact_decorator.rb
pact_broker-2.93.2 lib/pact_broker/api/decorators/extended_pact_decorator.rb
pact_broker-2.93.1 lib/pact_broker/api/decorators/extended_pact_decorator.rb