lib/onsi/model.rb in onsi-1.1.0 vs lib/onsi/model.rb in onsi-1.2.0
- old
+ new
@@ -46,12 +46,12 @@
#
# @param version [Symbol] The version that will trigger this render block.
#
# @param block [Block] The block. Called on an instance
# of {Onsi::Model::ModelRenderer}
- def api_render(version, &block)
- api_renderer(version).instance_exec(&block)
+ def api_render(version, id: :id, &block)
+ api_renderer(version, id).instance_exec(&block)
end
##
# Fetch the {Onsi::Model::ModelRenderer} for the version.
#
@@ -61,16 +61,16 @@
# required to exist. Should only ever be true when attempting to render
# the resource.
#
# @raise [Onsi::Errors::UnknownVersionError] If the version isn't defined
# and the for_render param is true.
- def api_renderer(version, for_render: false)
+ def api_renderer(version, id, for_render: false)
@api_renderer ||= {}
if for_render
raise Errors::UnknownVersionError.new(self, version) if @api_renderer[version].nil?
else
- @api_renderer[version] ||= ModelRenderer.new
+ @api_renderer[version] ||= ModelRenderer.new(id)
end
@api_renderer[version]
end
end
@@ -90,13 +90,18 @@
##
# The default date-time format for a rendered Date and Time. (ISO-8601)
DATETIME_FORMAT = '%Y-%m-%dT%H:%M:%SZ'.freeze
##
+ # The name of the id attribute on the model
+ attr_reader :id_attr
+
+ ##
# Create a new ModelRenderer
#
# @private
- def initialize
+ def initialize(id_attr)
+ @id_attr = id_attr
@attributes = {}
@relationships = {}
@metadata = {}
end