summaryrefslogtreecommitdiff
path: root/app/models/concerns/blocks_json_serialization.rb
blob: 18c00532d780832a5b2cfcceb979157002d2e6cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# frozen_string_literal: true

# Overrides `as_json` and `to_json` to raise an exception when called in order
# to prevent accidentally exposing attributes
#
# Not that would ever happen... but just in case.
module BlocksJsonSerialization
  extend ActiveSupport::Concern

  JsonSerializationError = Class.new(StandardError)

  def to_json(*)
    raise JsonSerializationError,
      "JSON serialization has been disabled on #{self.class.name}"
  end

  alias_method :as_json, :to_json
end