class Pact::Hal::Entity

Public Class Methods

new(href, data, http_client, response = nil) click to toggle source
# File lib/pact/hal/entity.rb, line 14
def initialize(href, data, http_client, response = nil)
  @href = href
  @data = data
  @links = (@data || {}).fetch("_links", {})
  @client = http_client
  @response = response
end

Public Instance Methods

assert_success!() click to toggle source
# File lib/pact/hal/entity.rb, line 82
def assert_success!
  self
end
can?(key) click to toggle source
# File lib/pact/hal/entity.rb, line 34
def can?(key)
  @links.key? key.to_s
end
fetch(key, fallback_key = nil) click to toggle source
# File lib/pact/hal/entity.rb, line 64
def fetch(key, fallback_key = nil)
  @links[key] || (fallback_key && @links[fallback_key])
end
follow(key, http_method, *args) click to toggle source
# File lib/pact/hal/entity.rb, line 38
def follow(key, http_method, *args)
  Link.new(@links[key].merge(method: http_method), @client).run(*args)
end
get(key, *args) click to toggle source
# File lib/pact/hal/entity.rb, line 22
def get(key, *args)
  _link(key).get(*args)
end
method_missing(method_name, *args, &block) click to toggle source
Calls superclass method
# File lib/pact/hal/entity.rb, line 68
def method_missing(method_name, *args, &block)
  if @data.key?(method_name.to_s)
    @data[method_name.to_s]
  elsif @links.key?(method_name)
    Link.new(@links[method_name], @client).run(*args)
  else
    super
  end
end
post(key, *args) click to toggle source
# File lib/pact/hal/entity.rb, line 26
def post(key, *args)
  _link(key).post(*args)
end
put(key, *args) click to toggle source
# File lib/pact/hal/entity.rb, line 30
def put(key, *args)
  _link(key).put(*args)
end
respond_to_missing?(method_name, include_private = false) click to toggle source
# File lib/pact/hal/entity.rb, line 78
def respond_to_missing?(method_name, include_private = false)
  @data.key?(method_name) || @links.key?(method_name)
end
response() click to toggle source
# File lib/pact/hal/entity.rb, line 60
def response
  @response
end
success?() click to toggle source
# File lib/pact/hal/entity.rb, line 56
def success?
  true
end