Class: DeviseTokenAuth::ResourceErrorsSerializer

Inherits:
Object
  • Object
show all
Defined in:
app/serializers/devise_token_auth/resource_errors_serializer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ ResourceErrorsSerializer

Returns a new instance of ResourceErrorsSerializer.



3
4
5
# File 'app/serializers/devise_token_auth/resource_errors_serializer.rb', line 3

def initialize(*args)
  @args = args
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



7
8
9
# File 'app/serializers/devise_token_auth/resource_errors_serializer.rb', line 7

def args
  @args
end

Instance Method Details

#as_json(options) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/serializers/devise_token_auth/resource_errors_serializer.rb', line 9

def as_json(options)
  resource = args[0]
  response = {
    status: "error",
    data: resource.as_json(except: [:tokens, :created_at, :updated_at])
  }
  if args.length > 1
    args.shift
    response[:errors] = args
  else
    response[:errors] = resource.errors.to_hash.merge(full_messages: resource.errors.full_messages)
  end
  response
end