Module: JSONAPI::Exceptions::UserDefinedExceptions

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

Overview

Allows a user of the gem to define extra requirements they want the middlewar to check for.

Defined Under Namespace

Classes: InvalidComponent, InvalidDocument, InvalidHeader, InvalidQueryParam

Class Method Summary collapse

Class Method Details

.check_user_document_requirements(document, config_manager, opts) ⇒ NilClass | String

Performs compliance checks on the document to see if it complies

to the user defined requirements

Parameters:

  • document (Hash)

    The hash representation of the json body

  • config_manager (JSONAPI::ConfigManager)

    The config_manager option to retreive user requirements from

Returns:

  • (NilClass | String)

    Nil or the String Error Message



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/easy/jsonapi/exceptions/user_defined_exceptions.rb', line 43

def check_user_document_requirements(document, config_manager, opts)
  return if config_manager.nil?
  
  config = get_config(config_manager, opts[:http_method], opts[:path])
  err = check_for_client_generated_id(document, config.allow_client_ids, opts[:http_method])
  
  return if config.default? && config_manager.size.positive?
  
  if err.nil?
    err = check_for_required_document_members(document, config.required_document_members)
  end
  # To add more user requirement features, add more methods here
  
  JSONAPI::Exceptions::UserDefinedExceptions::InvalidDocument.new(err) unless err.nil?
end

.check_user_header_requirements(headers, config_manager, opts) ⇒ Object

Performs compliance checks on the headers to see if it complies

to the user defined requirements

Parameters:

  • headers (Hash | JSONAPI::HeaderCollection)

    The collection of provided headers. Keys should be upper case strings with underscores instead of dashes.



64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/easy/jsonapi/exceptions/user_defined_exceptions.rb', line 64

def check_user_header_requirements(headers, config_manager, opts)
  return if config_manager.nil?
  
  config = get_config(config_manager, opts[:http_method], opts[:path])
  return if config.default? && config_manager.size.positive?

  err = 
    check_for_required_headers(headers, config.required_headers)
  # To add more user requirement features, add more methods here

  JSONAPI::Exceptions::UserDefinedExceptions::InvalidHeader.new(err) unless err.nil?
end

.check_user_query_param_requirements(rack_req_params, config_manager, opts) ⇒ Object

Performs compliance checks on the query params to see if it complies

to the user defined requirements

Parameters:

  • rack_req_params (Hash)

    The hash of the query parameters given by Rack::Request



81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/easy/jsonapi/exceptions/user_defined_exceptions.rb', line 81

def check_user_query_param_requirements(rack_req_params, config_manager, opts)
  return if config_manager.nil?
  
  config = get_config(config_manager, opts[:http_method], opts[:path])
  return if config.default? && config_manager.size.positive?

  err = 
    check_for_required_params(rack_req_params, config.required_query_params)
  # To add more user requirement features, add more methods here

  JSONAPI::Exceptions::UserDefinedExceptions::InvalidQueryParam.new(err) unless err.nil?
end