lib/transcriber/resource/response.rb in transcriber-0.0.17 vs lib/transcriber/resource/response.rb in transcriber-0.0.18
- old
+ new
@@ -3,24 +3,26 @@
module Response
extend ActiveSupport::Concern
def resource(options = {})
root = options.fetch(:root, true)
+
{}.tap do |resource|
resource_keys(options).inject(resource) do |buffer, key|
buffer.merge!(key.to_resource(self))
end
+
resource.merge!({link: link}) if root and self.class.relations.any?
end
end
def link
self.class.relations.map {|key| key.to_relation(self)}
end
def resource_keys(options)
- return self.class.keys unless summarize?(options)
- self.class.summarized_keys + [Resource::Href.new]
+ summarize?(options) ? self.class.summarized_keys + [Resource::Href.new]
+ : self.class.keys
end
def summarize?(options)
options[:summarize] and self.class.summarized_keys.any?
end