Module: Cetacean::Resource

Extended by:
Forwardable
Included in:
EmbeddedResource, Response
Defined in:
lib/cetacean/resource.rb

Instance Method Summary collapse

Instance Method Details

#attributesObject



10
11
12
# File 'lib/cetacean/resource.rb', line 10

def attributes
  hal.except('_links', '_embedded')
end

#embedded(rel = nil) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/cetacean/resource.rb', line 14

def embedded(rel=nil)
  return hal['_embedded'] if rel.nil?

  rel = rel.to_s

  if (document = embedded[rel])
    case document
    when Array
      Cetacean::EmbeddedResourceCollection.new(document)
    else
      Cetacean::EmbeddedResource.new(document)
    end
  end
end

#get_uri(rel) ⇒ Object



29
30
31
32
33
# File 'lib/cetacean/resource.rb', line 29

def get_uri(rel)
  return unless links.include?(rel.to_s)

  URITemplate.new(links[rel.to_s]['href'])
end


35
36
37
# File 'lib/cetacean/resource.rb', line 35

def links
  hal['_links'] || {}
end