blob: 826bd7038f168ed5ad1db42a30022be25065c8f4 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# frozen_string_literal: true
module ActiveModel
module Type
class ImmutableString < Value # :nodoc:
def type
:string
end
def serialize(value)
case value
when ::Numeric, ActiveSupport::Duration then value.to_s
when true then "t"
when false then "f"
else super
end
end
private
def cast_value(value)
result = \
case value
when true then "t"
when false then "f"
else value.to_s
end
result.freeze
end
end
end
end
|