module JSONAPI::Exceptions::NamingExceptions

Checking for JSONAPI naming rules compliance

Checking for JSONAPI naming rules compliance

Public Class Methods

check_additional_constraints(name) click to toggle source

JSONAPI implementation specific query parameters follow the same constraints as member names

with the additional requirement that they must also contain at least one non a-z character.

@param name [String] The string to check for

# File lib/easy/jsonapi/exceptions/naming_exceptions.rb, line 29
def self.check_additional_constraints(name)
  name = name.to_s
  return nil unless (name =~ /[^a-z]/).nil?
  'Implementation specific query parameters MUST contain at least one non a-z character'
end
check_member_constraints(name) click to toggle source

JSONAPI member names can only contain a-z, A-Z, 0-9, '-', '_', and the last two cannot be used

at the start or end of a member name.

@param name [String] The string to check for member name rule compliance @return

# File lib/easy/jsonapi/exceptions/naming_exceptions.rb, line 13
def self.check_member_constraints(name)
  name = name.to_s
  return 'Member names MUST contain at least one character' if name == ''
  unless (name =~ /[^a-zA-Z0-9_-]/).nil?
    return 'Member names MUST contain only the allowed characters: ' \
            "a-z, A-Z, 0-9, '-', '_'"
  end
  unless (name[0] =~ /[-_]/).nil? && (name[-1] =~ /[-_]/).nil?
    return 'Member names MUST start and end with a globally allowed character'
  end
  nil
end