Class: Discodactyl::JRD::Document

Inherits:
Hash
  • Object
show all
Defined in:
lib/discodactyl/jrd/document.rb

Direct Known Subclasses

HostMetaJRD

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse(raw) ⇒ Object


9
10
11
12
13
14
15
16
17
# File 'lib/discodactyl/jrd/document.rb', line 9

def self.parse(raw)
  begin
    Discodactyl.log.debug("parsing jrd: #{raw}") if Discodactyl.log
    decoded = ActiveSupport::JSON.decode(raw)
  rescue => e
    raise ParseError.new(e.message)
  end
  self.[](decoded)
end

Instance Method Details


33
34
35
36
37
# File 'lib/discodactyl/jrd/document.rb', line 33

def links
  rels.map do |rel, links|
    links.map {|link| Link.parse(link.merge('rel' => rel)) }
  end.flatten
end

25
26
27
28
29
30
31
# File 'lib/discodactyl/jrd/document.rb', line 25

def links_by_rel(rel)
  if self.has_key? 'links' and self['links'].has_key? rel
    self['links'][rel].map{|link| Link.parse(link.merge('rel'=>rel)) }
  else
    []
  end
end

#relsObject


39
40
41
# File 'lib/discodactyl/jrd/document.rb', line 39

def rels
  self['links'] || []
end

#subjectObject


43
44
45
# File 'lib/discodactyl/jrd/document.rb', line 43

def subject
  self['subject']
end

#uris_by_rel(rel, params = {}) ⇒ Object


19
20
21
22
23
# File 'lib/discodactyl/jrd/document.rb', line 19

def uris_by_rel(rel, params={})
  links_by_rel(rel).map do |link|
    link.href || link.template.to_uri(params)
  end
end