Module: Xqsr3::Quality::ParameterChecking

Defined in:
lib/xqsr3/quality/parameter_checking.rb

Overview

Inclusion module that creates class and instance methods check_option() and check_parameter() that may be used to check option/parameter values and types.

Class Method Summary collapse

Class Method Details

.check_option(h, name, options = {}, &block) ⇒ Object

Specific form of the check_parameter() that is used to check options, taking instead the hash and the key

Signature

  • Parameters:

    • h (::Hash) The options hash from which the named element is to be tested. May not be nil

    • name (::String, ::Symbol, [ ::String, ::Symbol ]) The options key name, or an array of names. May not be nil

    • options (::Hash) options that moderate the behaviour in the same way as for check_parameter() except that the :treat_as_option option (with the value true) is merged in before calling check_parameter()

  • Options:



215
216
217
218
# File 'lib/xqsr3/quality/parameter_checking.rb', line 215

def self.check_option h, name, options = {}, &block

  Util_.check_option h, name, options, &block
end

.check_param(value, name, options = {}, &block) ⇒ Object

Note:

This is obsolete, and will be removed in a future version.

Please use check_parameter instead

See Also:



199
200
201
202
# File 'lib/xqsr3/quality/parameter_checking.rb', line 199

def self.check_param value, name, options = {}, &block

  Util_.check_parameter value, name, options, &block
end

.check_parameter(value, name, options = {}, &block) ⇒ Object

Check a given parameter (value=value, name=name) for type and value

Signature

  • Parameters:

    • value the parameter whose value and type is to be checked

    • name the name of the parameter to be checked

    • options options

  • Options:

    • :allow_nil (boolean) The value must not be nil unless this option is true

    • :nil an alias for :allow_nil

    • :ignore_case (boolean) When :values is specified, comparisons of strings, or arrays of strings, will be carried out in a case-insensitive manner

    • :types (::Array) An array of types one of which value must be (or must be derived from). One of these types may be an array of types, in which case value may be an array that must consist wholly of those types

    • :type (::Class) A single type parameter, used only if :types is not specified

    • :values (::Array) an array of values one of which value must be

    • :responds_to (::Array) An array of symbols specifying all messages to which the parameter will respond

    • :reject_empty (boolean) requires value to respond to empty? message and to do so with false, unless nil

    • :require_empty (boolean) requires value to respond to empty? message and to do so with true, unless nil

    • :nothrow (boolean) causes failure to be indicated by a nil return rather than a thrown exception

    • :message (boolean) specifies a message to be used in any thrown exception, which suppresses internal message preparation

    • :treat_as_option (boolean) If true, the value will be treated as an option when reporting check failure



190
191
192
193
# File 'lib/xqsr3/quality/parameter_checking.rb', line 190

def self.check_parameter value, name, options = {}, &block

  Util_.check_parameter value, name, options, &block
end

.included(base) ⇒ Object

:nodoc:



105
106
107
108
# File 'lib/xqsr3/quality/parameter_checking.rb', line 105

def self.included base # :nodoc:

  base.extend self
end