class JSONAPIHelpers::Serializers::Errors

Public Class Methods

new() click to toggle source
# File lib/jsonapi_helpers/serializers/errors.rb, line 8
def initialize
  @errors = []
end

Public Instance Methods

add(**args) click to toggle source
# File lib/jsonapi_helpers/serializers/errors.rb, line 12
def add(**args)
  @errors << Error.new(**args)
end
each(&block) click to toggle source
# File lib/jsonapi_helpers/serializers/errors.rb, line 16
def each(&block)
  @errors.each(&block)
end
length() click to toggle source
# File lib/jsonapi_helpers/serializers/errors.rb, line 20
def length
  @errors.length
end
Also aliased as: size
size()
Alias for: length
to_h() click to toggle source
# File lib/jsonapi_helpers/serializers/errors.rb, line 25
def to_h
  { errors: @errors.map(&:to_h) }
end
to_json(_context = nil) click to toggle source

Rails is awkward and calls to_json with a context argument NOTE: Rails only method Hash#to_json

# File lib/jsonapi_helpers/serializers/errors.rb, line 31
def to_json(_context = nil)
  to_h.to_json
end