lib/jsonapi/resource_serializer.rb in jsonapi-resources-0.4.0 vs lib/jsonapi/resource_serializer.rb in jsonapi-resources-0.4.1
- old
+ new
@@ -65,10 +65,14 @@
},
data: data
}
end
+ def find_link(query_params)
+ "#{@base_url}/#{formatted_module_path_from_klass(@primary_resource_klass)}#{@route_formatter.format(@primary_resource_klass._type.to_s)}?#{query_params.to_query}"
+ end
+
private
# Process the primary source object(s). This will then serialize associated object recursively based on the
# requested includes. Fields are controlled fields option for each resource type, such
# as fields: { people: [:id, :email, :comments], posts: [:id, :title, :author], comments: [:id, :body, :post]}
# The fields options controls both fields and included links references.
@@ -198,10 +202,14 @@
links
end
def formatted_module_path(source)
- source.class.name =~ /::[^:]+\Z/ ? (@route_formatter.format($`).freeze.gsub('::', '/') + '/').downcase : ''
+ formatted_module_path_from_klass(source.class)
+ end
+
+ def formatted_module_path_from_klass(klass)
+ klass.name =~ /::[^:]+\Z/ ? (@route_formatter.format($`).freeze.gsub('::', '/') + '/').downcase : ''
end
def self_href(source)
"#{@base_url}/#{formatted_module_path(source)}#{@route_formatter.format(source.class._type.to_s)}/#{source.id}"
end