Module: JSONAPI::Exceptions::NamingExceptions

Defined in:
lib/easy/jsonapi/exceptions.rb,
lib/easy/jsonapi/exceptions/naming_exceptions.rb

Overview

Checking for JSONAPI naming rules compliance

Class Method Summary collapse

Class Method Details

.check_additional_constraints(name) ⇒ Object

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.

Parameters:

  • name (String)

    The string to check for



29
30
31
32
33
# 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) ⇒ Object

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.

Parameters:

  • name (String)

    The string to check for member name rule compliance

Returns:



13
14
15
16
17
18
19
20
21
22
23
24
# 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