Module: SimpleCrud::Serializer

Defined in:
lib/simple_crud/serializer.rb

Overview

Renders a record with the app's serializer stack.

Blueprinter blueprints respond to render_as_hash and receive the render options, so a blueprint can read url_builder: (or any other option) from them. For anything else, simple_crud assumes an ActiveModelSerializers-style serializer and calls new(record, options). A nil serializer renders record.as_json.

Class Method Summary collapse

Class Method Details

.render(serializer, record, options = {}) ⇒ Object



12
13
14
15
16
17
# File 'lib/simple_crud/serializer.rb', line 12

def self.render(serializer, record, options = {})
  return record.as_json if serializer.nil?
  return serializer.render_as_hash(record, options) if serializer.respond_to?(:render_as_hash)

  serializer.new(record, options).as_json
end