Sha256: 7cdba97577ea3e4da404745b782568fab4fee3ae5dfc9dc92048215a8c85592e
Contents?: true
Size: 1.33 KB
Versions: 1
Compression:
Stored size: 1.33 KB
Contents
# frozen_string_literal: true module SimplySerializable module Mixin module ClassMethods def inherited(subclass) subclass.serialize(**serialize_config) super(subclass) end def serialize(attributes: [], except: nil, only: nil) serializable_config[:attributes] = serializable_config[:attributes] |= attributes unless except.nil? serializable_config[:except] ||= [] serializable_config[:except] = serializable_config[:except] |= except end unless only.nil? serializable_config[:only] ||= [] serializable_config[:only] = serializable_config[:only] |= only end end def serializable_config @serializable_config ||= { attributes: [], except: nil, only: nil } end end def self.included(base) base.include(Fingerprintable::Mixin) base.extend(ClassMethods) end def serialize(cache: {}) serializer(cache: cache).serialize end def serializer(cache: {}) Serializer.new( **self.class.serializable_config.merge( cache: cache, object: self ) ) end def serializable_id "#{serializable_type}/#{fingerprint}" end def serializable_type self.class.name end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
simply_serializable-1.2.1 | lib/simply_serializable/mixin.rb |