lib/rest_model/response.rb in rest_model-0.2.1 vs lib/rest_model/response.rb in rest_model-0.2.3
- old
+ new
@@ -8,18 +8,17 @@
{}.tap do |resource|
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]
- links = build_links
- resource.merge!({link: links}) if links.any?
+ if (links = build_links).any? && !options[:summarize]
+ resource.merge!(link: links)
end
end
end
def build_links
- self.class.relations.map {|key| key.to_relation(self)}.reject(&:nil?)
+ self.class.relations.map {|key| key.to_relation(self)}.compact
end
def resource_keys(options)
summarize?(options) ? self.class.summarized_keys + [Href.new] : self.class.keys
end