Sha256: 6ce6fe91c9238647c67bf973d0259b064f58257cf1b633c404bcc1d289ff5f54

Contents?: true

Size: 948 Bytes

Versions: 6

Compression:

Stored size: 948 Bytes

Contents

require 'uri'
require 'delegate'

module PactBroker
  module Client
    module Hal
      class Links
        def initialize(href, key, links)
          @href = href
          @key = key
          @links = links
        end

        def names
          @names ||= links.collect(&:name).compact.uniq
        end

        def find!(name, not_found_message = nil)
          link = find(name)
          if link
            link
          else
            message = not_found_message || "Could not find relation '#{key}' with name '#{name}' in resource at #{href}."
            available_options = names.any? ? names.join(", ") : "<none found>"
            raise RelationNotFoundError.new(message.chomp(".") + ". Available options: #{available_options}")
          end
        end

        def find(name)
          links.find{ | link | link.name == name }
        end

        private

        attr_reader :links, :key, :href
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
pact_broker-client-1.38.3 lib/pact_broker/client/hal/links.rb
pact_broker-client-1.38.2 lib/pact_broker/client/hal/links.rb
pact_broker-client-1.38.1 lib/pact_broker/client/hal/links.rb
pact_broker-client-1.38.0 lib/pact_broker/client/hal/links.rb
pact_broker-client-1.37.1 lib/pact_broker/client/hal/links.rb
pact_broker-client-1.37.0 lib/pact_broker/client/hal/links.rb