Module: RazorRisk::Cassini::Applications::RouteVerbAdaptors::Utilities::CollectionGetHelper

Includes:
Pantheios, Xqsr3::Quality::ParameterChecking
Defined in:
lib/razor_risk/cassini/applications/route_verb_adaptors/utilities/collection_get_helper.rb

Overview

########################################################################## modules

Instance Method Summary collapse

Instance Method Details

#validate_exclusive_search_parameters(params, *search_parameter_names, **options) ⇒ Object

This function validates that at most of the given search_parameter_names is specified in the params hash, or issues a halt with a suitable message

Signature

  • Parameters:
@param params

(::Hash) The verb handler adaptor's params attribute. May not be nil

@param search_parameter_names

(::Array) The names of the query parameters to validate

@param options

(::Hash) Options

  • Options: @option :halt_code:: (::Integer) Specifies the halt code to be issued. Defaults to 422. If 0, the function does not call halt, and instead returns false @option :message_scope:: (::String) The scoping part of the message. Defaults to 'invalid search specifier'. If specified as the empty string no scoping part will be included in the halt message


57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/razor_risk/cassini/applications/route_verb_adaptors/utilities/collection_get_helper.rb', line 57

def validate_exclusive_search_parameters params, *search_parameter_names, **options

    halt_code       =   Integer(options[:halt_code] || 422)

    message_scope   =   options[:message_scope] || 'invalid search specifier'
    message_scope   +=  ': ' unless message_scope.empty?

    names_present   =   search_parameter_names.select { |name| params[name] }.sort

    case names_present.count
    when 0, 1

        true
    else

        halt *[ halt_code, {}, "#{message_scope}cannot specify '#{names_present[0]}' and '#{names_present[1]}' together" ]
    end
end