Sha256: d03f2b3533cfa63f038f3cd71d384b23dba8f359cfab75694964f7f6d92d18f6
Contents?: true
Size: 585 Bytes
Versions: 8
Compression:
Stored size: 585 Bytes
Contents
module EnumIsh class ActiveRecordEnumType < ActiveRecord::Type::Value def initialize(name, mapping, subtype) @name = name @mapping = mapping @subtype = subtype end def cast(value) return if value.nil? if @mapping.has_key?(value.to_s.to_sym) value.to_s.to_sym elsif @mapping.has_value?(value) @mapping.key(value) else value end end def deserialize(value) @mapping.key(@subtype.deserialize(value)) end def serialize(value) @mapping.fetch(value, value) end end end
Version data entries
8 entries across 8 versions & 1 rubygems