Sha256: 35319bb73efaf865204d4a6540a9a1a01a8c3593f8fe1bc02c56866b9ab918df
Contents?: true
Size: 719 Bytes
Versions: 3
Compression:
Stored size: 719 Bytes
Contents
# frozen_string_literal: true require "json" module ActiveFunction class DoubleRenderError < Error MESSAGE_TEMPLATE = "#render was called multiple times in action: %s" attr_reader :message def initialize(context) @message = MESSAGE_TEMPLATE % context end end module Functions module Rendering DEFAULT_HEADER = {"Content-Type" => "application/json"}.freeze def render(status: 200, json: {}, head: {}) raise DoubleRenderError, @action_name if performed? @response.status = status @response.headers = head.merge(Hash[DEFAULT_HEADER]) @response.body = JSON.generate(json) @response.commit! end end end end
Version data entries
3 entries across 3 versions & 1 rubygems