lib/rest_model/response.rb in rest_model-0.1.11 vs lib/rest_model/response.rb in rest_model-0.1.12
- old
+ new
@@ -9,21 +9,21 @@
resource_keys(options).inject(resource) do |buffer, key|
buffer.merge!(key.to_resource(self))
end
if root and self.class.relations.any? and !options[:summarize]
- resource.merge!({link: link})
+ links = build_links
+ resource.merge!({link: links}) if links.any?
end
end
end
- def link
- self.class.relations.map {|key| key.to_relation(self)}
+ def build_links
+ self.class.relations.map {|key| key.to_relation(self)}.reject(&:nil?)
end
def resource_keys(options)
- summarize?(options) ? self.class.summarized_keys + [Href.new]
- : self.class.keys
+ summarize?(options) ? self.class.summarized_keys + [Href.new] : self.class.keys
end
def summarize?(options)
options[:summarize] and self.class.summarized_keys.any?
end