Module: Frenetic::Related
- Extended by:
- StructureMethodDefiner
- Included in:
- Resource
- Defined in:
- lib/frenetic/concerns/related.rb
Instance Method Summary collapse
Methods included from StructureMethodDefiner
Instance Method Details
#extract_related_resources ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/frenetic/concerns/related.rb', line 15 def links.each do |k, attrs| next if k == 'self' Array.wrap(attrs).each do |relation| relations[k] = relation end end end |
#fetch_related_resource(relation, props) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/frenetic/concerns/related.rb', line 24 def (relation, props) begin response = api.get(props['href']) rescue ClientParsingError, ClientError => ex raise if ex.status != 404 raise ResourceNotFound.new(self, props) end return nil unless response.success? resource_class = self.class.find_resource_class(relation) if collection?(relation) self.class.(response.body).fetch(relation, []) else resource_class.new(response.body) end end |