Sha256: d34620eec4d5549e5b58e4ee8621a041848217db80e1e49036d820454f293e27
Contents?: true
Size: 717 Bytes
Versions: 52
Compression:
Stored size: 717 Bytes
Contents
# frozen_string_literal: true module Alchemy class BaseSerializer include ActiveModel::Serializers::JSON attr_reader :object, :opts def initialize(object, opts = {}) @object = object @opts = opts end # The attributes to be serialized. See ActiveModel::Serialization. # By default, serialize all columns from the AR object. def attributes object.class.column_names.map { |c| [c, nil] }.to_h end private # If the presenter implements an attribute, use that. Otherwise, delegate to # the object. def read_attribute_for_serialization(key) if respond_to?(key) send(key) else object.send(key) end end end end
Version data entries
52 entries across 52 versions & 1 rubygems