Sha256: bc0f51d4fb60f710aba5a90be0d30f09d3116f08e06b52075914676e98a5a856
Contents?: true
Size: 687 Bytes
Versions: 22
Compression:
Stored size: 687 Bytes
Contents
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
22 entries across 22 versions & 1 rubygems