class PactBroker::Client::Hal::Links

Attributes

href[R]
key[R]

Public Class Methods

new(href, key, links) click to toggle source
# File lib/pact_broker/client/hal/links.rb, line 11
def initialize(href, key, links)
  @href = href
  @key = key
  @links = links
end

Public Instance Methods

find(name) click to toggle source
# File lib/pact_broker/client/hal/links.rb, line 32
def find(name)
  links.find{ | link | link.name == name }
end
find!(name, not_found_message = nil) click to toggle source
# File lib/pact_broker/client/hal/links.rb, line 21
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
names() click to toggle source
# File lib/pact_broker/client/hal/links.rb, line 17
def names
  @names ||= links.collect(&:name).compact.uniq
end
select(name) click to toggle source
# File lib/pact_broker/client/hal/links.rb, line 47
def select(name)
  links.select{ | link | link.name == name }
end
select!(name, not_found_message = nil) click to toggle source
# File lib/pact_broker/client/hal/links.rb, line 36
def select!(name, not_found_message = nil)
  selected_links = select(name)
  if selected_links.any?
    selected_links
  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