lib/onsi/resource.rb in onsi-1.1.0 vs lib/onsi/resource.rb in onsi-1.2.0
- old
+ new
@@ -152,11 +152,11 @@
#
# @return [Hash]
def as_json(_opts = {})
{}.tap do |root|
root[TYPE_KEY] = type
- root[ID_KEY] = object.id.to_s
+ root[ID_KEY] = object_id
root[ATTRIBUTES_KEY] = generate_attributes
append_relationships(root)
append_meta(root)
append_includes(root)
end
@@ -187,12 +187,17 @@
if includes.present? && !includes.is_a?(Onsi::Includes)
raise InvalidResourceError, "Included resources in #{self} is not a Onsi::Includes"
end
end
+ def object_id
+ attr = object.class.api_renderer(version, nil, for_render: true).id_attr
+ object.send(attr).to_s
+ end
+
def type
- object.class.api_renderer(version, for_render: true).type || object.class.name.underscore
+ object.class.api_renderer(version, nil, for_render: true).type || object.class.name.underscore
end
def append_relationships(root)
relationships = generate_relationships
return unless relationships.any?
@@ -214,18 +219,18 @@
root[RELATIONSHIPS_KEY] ||= {}
root[RELATIONSHIPS_KEY].merge!(includes)
end
def generate_attributes
- object.class.api_renderer(version, for_render: true).render_attributes(object)
+ object.class.api_renderer(version, nil, for_render: true).render_attributes(object)
end
def generate_relationships
- object.class.api_renderer(version, for_render: true).render_relationships(object)
+ object.class.api_renderer(version, nil, for_render: true).render_relationships(object)
end
def generate_metadata
- object.class.api_renderer(version, for_render: true).render_metadata(object)
+ object.class.api_renderer(version, nil, for_render: true).render_metadata(object)
end
def generate_includes
{}.tap do |root|
rendered_includes.each do |key, values|