Sha256: c51d89c87729b071dc58bc1e421a487884bd39d610455d4d747ebdba8457a63b
Contents?: true
Size: 718 Bytes
Versions: 127
Compression:
Stored size: 718 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 Hash[object.class.column_names.map { |c| [c, nil] }] 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
127 entries across 127 versions & 1 rubygems