Class: PGTrunk::Serializers::MultilineTextSerializer

Inherits:
ActiveRecord::Type::Value
  • Object
show all
Defined in:
lib/pg_trunk/core/serializers/multiline_text_serializer.rb

Overview

Cast the attribute value as a multiline text with right-stripped lines and without empty lines.

Instance Method Summary collapse

Instance Method Details

#cast(value) ⇒ Object



9
10
11
12
13
# File 'lib/pg_trunk/core/serializers/multiline_text_serializer.rb', line 9

def cast(value)
  return if value.blank?

  value.to_s.lines.map(&:strip).reject(&:blank?).join("\n")
end

#serialize(value) ⇒ Object



15
16
17
# File 'lib/pg_trunk/core/serializers/multiline_text_serializer.rb', line 15

def serialize(value)
  value&.to_s
end