Sha256: bf6c30357bd3d88d577dc7684330a3599cacad9536429cf87a74a4131a6d2b26

Contents?: true

Size: 448 Bytes

Versions: 5

Compression:

Stored size: 448 Bytes

Contents

# frozen_string_literal: true

# @private
module PGTrunk::Serializers
  # @private
  # Cast the attribute value as a non-empty stripped string in lowercase
  class LowercaseStringSerializer < ActiveRecord::Type::Value
    def cast(value)
      value.to_s.presence&.downcase&.strip
    end

    def serialize(value)
      value.to_s
    end
  end

  ActiveModel::Type.register(
    :pg_trunk_lowercase_string,
    LowercaseStringSerializer,
  )
end

Version data entries

5 entries across 5 versions & 1 rubygems

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