mirror of
https://github.com/discourse/discourse.git
synced 2025-05-29 21:27:58 +08:00
DEV: Move more service code to core (#26613)
This is to enable :array type attributes for Contract attributes in services, this is a followup to the move of services from chat to core here: cab178a40557e205e9c3e75fcb411a5e0e164d15 Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
This commit is contained in:
@ -1,32 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Chat
|
||||
module Types
|
||||
class Array < ActiveModel::Type::Value
|
||||
def serializable?(_)
|
||||
false
|
||||
end
|
||||
|
||||
def cast_value(value)
|
||||
case value
|
||||
when String
|
||||
value.split(",")
|
||||
when ::Array
|
||||
value.map { |item| convert_to_integer(item) }
|
||||
else
|
||||
::Array.wrap(value)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def convert_to_integer(item)
|
||||
Integer(item)
|
||||
rescue ArgumentError
|
||||
item
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
ActiveSupport.on_load(:active_record) { ActiveModel::Type.register(:array, Chat::Types::Array) }
|
Reference in New Issue
Block a user