Skip to content

Commit

Permalink
Make Rails EnumType handle serializing pre-serialized values (#256)
Browse files Browse the repository at this point in the history
Co-authored-by: Stephen Margheim <[email protected]>
  • Loading branch information
joeldrapper and fractaledmind authored Dec 11, 2024
1 parent 475cec2 commit c7f8fbe
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/literal/rails/enum_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ def serialize(value)
when @enum
value.value
else
raise Literal::ArgumentError.new(
"Invalid value: #{value.inspect}. Expected an #{@enum.inspect}.",
)
if @enum[value]
value
else
raise Literal::ArgumentError.new(
"Invalid value: #{value.inspect}. Expected an #{@enum.inspect}.",
)
end
end
end

Expand Down

0 comments on commit c7f8fbe

Please sign in to comment.