Module: Blueprinter::Rendering Private
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Encapsulates the rendering logic for Blueprinter.
Instance Method Summary collapse
-
#hashify(object, view_name:, local_options:) ⇒ Hash
private
Converts an object into a Hash representation based on provided view.
-
#prepare(object, view_name:, local_options:) ⇒ Object
deprecated
private
Deprecated.
This method is no longer supported, and was not originally intended to be public. This will be removed in the next minor release. If similar functionality is needed, use ‘.render_as_hash` instead.
-
#render(object, options = {}) ⇒ String
private
Generates a JSON formatted String represantation of the provided object.
-
#render_as_hash(object, options = {}) ⇒ Hash
private
Generates a Hash representation of the provided object.
-
#render_as_json(object, options = {}) ⇒ Hash
private
Generates a JSONified hash.
Instance Method Details
#hashify(object, view_name:, local_options:) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts an object into a Hash representation based on provided view.
92 93 94 95 96 97 |
# File 'lib/blueprinter/rendering.rb', line 92 def hashify(object, view_name:, local_options:) raise BlueprinterError, "View '#{view_name}' is not defined" unless view_collection.view?(view_name) object = Blueprinter.configuration.extensions.pre_render(object, self, view_name, ) prepare_data(object, view_name, ) end |
#prepare(object, view_name:, local_options:) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method is no longer supported, and was not originally intended to be public. This will be removed in the next minor release. If similar functionality is needed, use ‘.render_as_hash` instead.
This is the magic method that converts complex objects into a simple hash ready for JSON conversion.
Note: we accept view (public interface) that is in reality a view_name, so we rename it for clarity
109 110 111 112 113 114 115 116 117 |
# File 'lib/blueprinter/rendering.rb', line 109 def prepare(object, view_name:, local_options:) Blueprinter::Deprecation.report( <<~MESSAGE The `prepare` method is no longer supported will be removed in the next minor release. If similar functionality is needed, use `.render_as_hash` instead. MESSAGE ) render_as_hash(object, view_name:, local_options:) end |
#render(object, options = {}) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Generates a JSON formatted String represantation of the provided object.
31 32 33 |
# File 'lib/blueprinter/rendering.rb', line 31 def render(object, = {}) jsonify(build_result(object: object, options: )) end |
#render_as_hash(object, options = {}) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Generates a Hash representation of the provided object. Takes a required object and an optional view.
56 57 58 |
# File 'lib/blueprinter/rendering.rb', line 56 def render_as_hash(object, = {}) build_result(object: object, options: ) end |
#render_as_json(object, options = {}) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Generates a JSONified hash. Takes a required object and an optional view.
81 82 83 |
# File 'lib/blueprinter/rendering.rb', line 81 def render_as_json(object, = {}) build_result(object: object, options: ).as_json end |