@ -385,15 +385,17 @@ class Account < ApplicationRecord
end
end
class Field < ActiveModelSerializers :: Model
class Field < ActiveModelSerializers :: Model
attributes :name , :value , :verified_at , :account , :errors
attributes :name , :value , :verified_at , :account
def initialize ( account , attributes )
def initialize ( account , attributes )
@account = account
@original_field = attributes
@attributes = attributes
string_limit = account . local? ? 255 : 2047
@name = attributes [ 'name' ] . strip [ 0 , string_limit ]
super (
@value = attributes [ 'value' ] . strip [ 0 , string_limit ]
account : account ,
@verified_at = attributes [ 'verified_at' ] & . to_datetime
name : attributes [ 'name' ] . strip [ 0 , string_limit ] ,
@errors = { }
value : attributes [ 'value' ] . strip [ 0 , string_limit ] ,
verified_at : attributes [ 'verified_at' ] & . to_datetime ,
)
end
end
def verified?
def verified?
@ -415,22 +417,12 @@ class Account < ApplicationRecord
end
end
def mark_verified!
def mark_verified!
@ verified_at = Time . now . utc
self . verified_at = Time . now . utc
@ attributes[ 'verified_at' ] = @ verified_at
@ original_field[ 'verified_at' ] = verified_at
end
end
def to_h
def to_h
{ name : @name , value : @value , verified_at : @verified_at }
{ name : name , value : value , verified_at : verified_at }
end
private
def string_limit
if account . local?
255
else
2047
end
end
end
end
end