Sha256: ed7635a0b9165a313669301d60b5d2cfbbe0791be2cc5a97337b22e9d21ffe99

Contents?: true

Size: 480 Bytes

Versions: 5

Compression:

Stored size: 480 Bytes

Contents

# frozen_string_literal: true

# @private
module PGTrunk::Serializers
  # @private
  # Cast the attribute value as a symbol.
  class SymbolSerializer < ActiveRecord::Type::Value
    def cast(value)
      return if value.blank?
      return value if value.is_a?(Symbol)
      return value.to_sym if value.respond_to?(:to_sym)

      value.to_s.to_sym
    end

    def serialize(value)
      value
    end
  end

  ActiveModel::Type.register(:pg_trunk_symbol, SymbolSerializer)
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pg_trunk-0.2.0 lib/pg_trunk/core/serializers/symbol_serializer.rb
pg_trunk-0.1.3 lib/pg_trunk/core/serializers/symbol_serializer.rb
pg_trunk-0.1.2 lib/pg_trunk/core/serializers/symbol_serializer.rb
pg_trunk-0.1.1 lib/pg_trunk/core/serializers/symbol_serializer.rb
pg_trunk-0.1.0 lib/pg_trunk/core/serializers/symbol_serializer.rb