Created
June 25, 2024 13:29
-
-
Save osbre/f80cfe5d885b9dc7599b583e7788c1d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Types | |
class AppendSuffixType < ActiveRecord::Type::String | |
def initialize(suffix) | |
@suffix = suffix.to_s | |
end | |
def cast_value(value) | |
value.to_s + @suffix unless value.nil? | |
end | |
def serialize(value) | |
value.chomp(@suffix) unless value.nil? | |
end | |
def changed_in_place?(original_value_for_database, value) | |
original_value_for_database != serialize(value) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment