xqsr3 0.32.2 → 0.36.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/xqsr3/all_extensions.rb +6 -0
- data/lib/xqsr3/array_utilities.rb +10 -0
- data/lib/xqsr3/array_utilities/join_with_or.rb +7 -14
- data/lib/xqsr3/command_line_utilities.rb +10 -0
- data/lib/xqsr3/command_line_utilities/map_option_string.rb +21 -8
- data/lib/xqsr3/containers.rb +11 -0
- data/lib/xqsr3/containers/frequency_map.rb +19 -2
- data/lib/xqsr3/containers/multi_map.rb +316 -27
- data/lib/xqsr3/conversion.rb +11 -0
- data/lib/xqsr3/conversion/bool_parser.rb +11 -14
- data/lib/xqsr3/conversion/integer_parser.rb +10 -16
- data/lib/xqsr3/diagnostics.rb +11 -0
- data/lib/xqsr3/diagnostics/exception_utilities.rb +2 -2
- data/lib/xqsr3/diagnostics/exceptions/with_cause.rb +15 -7
- data/lib/xqsr3/diagnostics/inspect_builder.rb +16 -16
- data/lib/xqsr3/doc_.rb +138 -9
- data/lib/xqsr3/extensions.rb +13 -0
- data/lib/xqsr3/extensions/array.rb +3 -0
- data/lib/xqsr3/extensions/array/join_with_or.rb +6 -0
- data/lib/xqsr3/extensions/enumerable/collect_with_index.rb +5 -4
- data/lib/xqsr3/extensions/enumerable/detect_map.rb +6 -7
- data/lib/xqsr3/extensions/hash.rb +5 -0
- data/lib/xqsr3/extensions/hash/has_match.rb +7 -0
- data/lib/xqsr3/extensions/hash/match.rb +7 -0
- data/lib/xqsr3/extensions/hash/slice.rb +22 -0
- data/lib/xqsr3/extensions/io/writelines.rb +38 -6
- data/lib/xqsr3/extensions/kernel/integer.rb +6 -13
- data/lib/xqsr3/extensions/string/to_bool.rb +4 -0
- data/lib/xqsr3/extensions/test/unit/assert_eql.rb +1 -0
- data/lib/xqsr3/extensions/test/unit/assert_false.rb +1 -0
- data/lib/xqsr3/extensions/test/unit/assert_not.rb +1 -0
- data/lib/xqsr3/extensions/test/unit/assert_not_eql.rb +1 -0
- data/lib/xqsr3/extensions/test/unit/assert_raise_with_message.rb +25 -4
- data/lib/xqsr3/extensions/test/unit/assert_subclass_of.rb +1 -0
- data/lib/xqsr3/extensions/test/unit/assert_superclass_of.rb +1 -0
- data/lib/xqsr3/extensions/test/unit/assert_true.rb +1 -0
- data/lib/xqsr3/extensions/test/unit/assert_type_has_instance_methods.rb +3 -12
- data/lib/xqsr3/hash_utilities.rb +11 -0
- data/lib/xqsr3/hash_utilities/deep_transform.rb +2 -2
- data/lib/xqsr3/hash_utilities/key_matching.rb +6 -4
- data/lib/xqsr3/internal_/test_unit_version_.rb +30 -4
- data/lib/xqsr3/io/writelines.rb +55 -19
- data/lib/xqsr3/quality.rb +8 -1
- data/lib/xqsr3/quality/parameter_checking.rb +52 -78
- data/lib/xqsr3/string_utilities.rb +16 -0
- data/lib/xqsr3/string_utilities/ends_with.rb +16 -7
- data/lib/xqsr3/string_utilities/nil_if_empty.rb +8 -4
- data/lib/xqsr3/string_utilities/nil_if_whitespace.rb +9 -4
- data/lib/xqsr3/string_utilities/quote_if.rb +12 -14
- data/lib/xqsr3/string_utilities/starts_with.rb +23 -5
- data/lib/xqsr3/string_utilities/to_symbol.rb +24 -5
- data/lib/xqsr3/string_utilities/truncate.rb +20 -4
- data/lib/xqsr3/version.rb +3 -2
- data/test/unit/containers/tc_multi_map.rb +174 -16
- data/test/unit/extensions/hash/tc_hash.rb +6 -0
- data/test/unit/extensions/hash/tc_slice.rb +31 -0
- data/test/unit/extensions/io/tc_writelines.rb +36 -0
- metadata +16 -3
@@ -6,13 +6,13 @@
|
|
6
6
|
# module
|
7
7
|
#
|
8
8
|
# Created: 15th November 2017
|
9
|
-
# Updated: 15th
|
9
|
+
# Updated: 15th April 2019
|
10
10
|
#
|
11
11
|
# Home: http://github.com/synesissoftware/xqsr3
|
12
12
|
#
|
13
13
|
# Author: Matthew Wilson
|
14
14
|
#
|
15
|
-
# Copyright (c) 2017, Matthew Wilson and Synesis Software
|
15
|
+
# Copyright (c) 2017-2019, Matthew Wilson and Synesis Software
|
16
16
|
# All rights reserved.
|
17
17
|
#
|
18
18
|
# Redistribution and use in source and binary forms, with or without
|
@@ -56,10 +56,12 @@ require 'xqsr3/quality/parameter_checking'
|
|
56
56
|
module Xqsr3
|
57
57
|
module HashUtilities
|
58
58
|
|
59
|
+
# +include+-able module that provides ::has_match?, #has_match?, ::match,
|
60
|
+
# and #match methods
|
59
61
|
module KeyMatching
|
60
62
|
|
61
63
|
private
|
62
|
-
def self.do_match_ h, re, **options
|
64
|
+
def self.do_match_ h, re, **options # :nodoc:
|
63
65
|
|
64
66
|
::Xqsr3::Quality::ParameterChecking.check_parameter h, 'h', responds_to: [ :[], :has_key?, :each ]
|
65
67
|
|
@@ -97,7 +99,7 @@ module KeyMatching
|
|
97
99
|
nil
|
98
100
|
end
|
99
101
|
|
100
|
-
def self.do_has_match_ h, re, **options
|
102
|
+
def self.do_has_match_ h, re, **options # :nodoc:
|
101
103
|
|
102
104
|
::Xqsr3::Quality::ParameterChecking.check_parameter h, 'h', responds_to: [ :[], :has_key?, :each ]
|
103
105
|
|
@@ -3,30 +3,47 @@
|
|
3
3
|
# Test::Unit module
|
4
4
|
|
5
5
|
require 'test/unit'
|
6
|
+
|
6
7
|
begin
|
7
8
|
|
8
9
|
require 'test/unit/version'
|
9
10
|
|
11
|
+
# :stopdoc:
|
12
|
+
# @!visibility private
|
10
13
|
module Xqsr3
|
11
|
-
|
12
|
-
module
|
14
|
+
# @!visibility private
|
15
|
+
module Internal_ # :nodoc:
|
16
|
+
# @!visibility private
|
17
|
+
module TestUnitVersion_ # :nodoc:
|
13
18
|
|
19
|
+
# @!visibility private
|
14
20
|
TEST_UNIT_VERSION_ = Test::Unit::VERSION # :nodoc:
|
15
21
|
end # module TestUnitVersion_
|
16
22
|
end # module Internal_
|
17
23
|
end # module Xqsr3
|
24
|
+
|
25
|
+
# :startdoc:
|
18
26
|
rescue LoadError
|
19
27
|
|
28
|
+
# :stopdoc:
|
29
|
+
# @!visibility private
|
20
30
|
module Xqsr3
|
21
|
-
|
22
|
-
module
|
31
|
+
# @!visibility private
|
32
|
+
module Internal_ # :nodoc:
|
33
|
+
# @!visibility private
|
34
|
+
module TestUnitVersion_ # :nodoc:
|
23
35
|
|
36
|
+
# @!visibility private
|
24
37
|
TEST_UNIT_VERSION_ = :not_found # :nodoc:
|
25
38
|
end # module TestUnitVersion_
|
26
39
|
end # module Internal_
|
27
40
|
end # module Xqsr3
|
41
|
+
|
42
|
+
# :startdoc:
|
28
43
|
end
|
29
44
|
|
45
|
+
# :stopdoc:
|
46
|
+
|
30
47
|
module Xqsr3
|
31
48
|
module Internal_ # :nodoc:
|
32
49
|
module TestUnitVersion_ # :nodoc:
|
@@ -47,6 +64,7 @@ module TestUnitVersion_ # :nodoc:
|
|
47
64
|
TEST_UNIT_VERSION_PATCH_ = TEST_UNIT_VERSION_PARTS_[2] # :nodoc:
|
48
65
|
end
|
49
66
|
|
67
|
+
# @!visibility private
|
50
68
|
def self.less_ a1, a2 # :nodoc:
|
51
69
|
|
52
70
|
n_common = a1.size < a2.size ? a1.size : a2.size
|
@@ -79,6 +97,7 @@ module TestUnitVersion_ # :nodoc:
|
|
79
97
|
end
|
80
98
|
end
|
81
99
|
|
100
|
+
# @!visibility private
|
82
101
|
def self.is_major_at_least? j # :nodoc:
|
83
102
|
|
84
103
|
return unless TEST_UNIT_VERSION_MAJOR_
|
@@ -86,6 +105,7 @@ module TestUnitVersion_ # :nodoc:
|
|
86
105
|
return j >= TEST_UNIT_VERSION_MAJOR_
|
87
106
|
end
|
88
107
|
|
108
|
+
# @!visibility private
|
89
109
|
def self.is_minor_at_least? n # :nodoc:
|
90
110
|
|
91
111
|
return unless TEST_UNIT_VERSION_MINOR_
|
@@ -93,6 +113,7 @@ module TestUnitVersion_ # :nodoc:
|
|
93
113
|
return n >= TEST_UNIT_VERSION_MINOR_
|
94
114
|
end
|
95
115
|
|
116
|
+
# @!visibility private
|
96
117
|
def self.is_at_least? v # :nodoc:
|
97
118
|
|
98
119
|
v = v.split(/\./).collect { |n| n.to_i } if String === v
|
@@ -100,6 +121,7 @@ module TestUnitVersion_ # :nodoc:
|
|
100
121
|
return !less_(TEST_UNIT_VERSION_PARTS_, v)
|
101
122
|
end
|
102
123
|
|
124
|
+
# @!visibility private
|
103
125
|
def self.is_less? v # :nodoc:
|
104
126
|
|
105
127
|
v = v.split(/\./).collect { |n| n.to_i } if String === v
|
@@ -111,4 +133,8 @@ end # module TestUnitVersion_
|
|
111
133
|
end # module Internal_
|
112
134
|
end # module Xqsr3
|
113
135
|
|
136
|
+
# :startdoc:
|
137
|
+
|
138
|
+
# ############################## end of file ############################# #
|
139
|
+
|
114
140
|
|
data/lib/xqsr3/io/writelines.rb
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
# Purpose: Adds a writelines() method to the IO module
|
6
6
|
#
|
7
7
|
# Created: 13th April 2007
|
8
|
-
# Updated:
|
8
|
+
# Updated: 31st October 2019
|
9
9
|
#
|
10
10
|
# Home: http://github.com/synesissoftware/xqsr3
|
11
11
|
#
|
@@ -56,27 +56,58 @@ module Xqsr3
|
|
56
56
|
module IO
|
57
57
|
|
58
58
|
private
|
59
|
-
|
59
|
+
# @!visibility private
|
60
|
+
module WriteLine_Constants_ #:nodoc: all
|
60
61
|
|
61
62
|
NUMBER_OF_LINES_TO_EXAMINE = 20
|
62
|
-
|
63
63
|
end # module WriteLine_Constants_
|
64
64
|
|
65
65
|
private
|
66
66
|
|
67
|
-
|
68
|
-
|
69
|
-
|
67
|
+
# @!visibility private
|
68
|
+
def self.write_to_target_ target, contents, line_separator, column_separator, no_last_eol # :nodoc:
|
69
|
+
|
70
|
+
$stderr.puts "#{self.class}.write_to_target_(target(#{target.class})='#{target}', contents(#{contents.class})='#{contents}', line_separator(#{line_separator.class})='#{line_separator}', column_separator(#{column_separator.class})='#{column_separator}', no_last_eol(#{no_last_eol.class})=#{no_last_eol})" if $DEBUG
|
71
|
+
|
72
|
+
if no_last_eol
|
73
|
+
|
74
|
+
first = true
|
75
|
+
|
76
|
+
if contents.instance_of? ::Hash
|
77
|
+
|
78
|
+
contents.each do |k, v|
|
79
|
+
|
80
|
+
target << line_separator unless first
|
81
|
+
|
82
|
+
target << "#{k}#{column_separator}#{v}"
|
83
|
+
|
84
|
+
first = false
|
85
|
+
end
|
86
|
+
else
|
70
87
|
|
71
|
-
|
88
|
+
contents.each do |element|
|
72
89
|
|
73
|
-
|
90
|
+
target << line_separator unless first
|
91
|
+
|
92
|
+
target << "#{element}"
|
93
|
+
|
94
|
+
first = false
|
95
|
+
end
|
74
96
|
end
|
75
97
|
else
|
76
98
|
|
77
|
-
contents.
|
99
|
+
if contents.instance_of? ::Hash
|
78
100
|
|
79
|
-
|
101
|
+
contents.each do |k, v|
|
102
|
+
|
103
|
+
target << "#{k}#{column_separator}#{v}#{line_separator}"
|
104
|
+
end
|
105
|
+
else
|
106
|
+
|
107
|
+
contents.each do |element|
|
108
|
+
|
109
|
+
target << "#{element}#{line_separator}"
|
110
|
+
end
|
80
111
|
end
|
81
112
|
end
|
82
113
|
|
@@ -87,7 +118,9 @@ $stderr.puts "#{self.class}.write_to_target_(target(#{target.class})='#{target}'
|
|
87
118
|
# embedded eol, in which case the empty string is returned to force no
|
88
119
|
# (additional) separator will be used. Otherwise, it returns "\n" to
|
89
120
|
# ensure that that is used.
|
90
|
-
|
121
|
+
#
|
122
|
+
# @!visibility private
|
123
|
+
def self.deduce_line_separator_ contents, eol_lookahead_limit # :nodoc:
|
91
124
|
|
92
125
|
if contents.instance_of? ::Hash
|
93
126
|
|
@@ -126,14 +159,15 @@ $stderr.puts "#{self.class}.write_to_target_(target(#{target.class})='#{target}'
|
|
126
159
|
# === Signature
|
127
160
|
#
|
128
161
|
# * *Parameters:*
|
129
|
-
# - +target
|
130
|
-
# - +contents
|
131
|
-
# - +options
|
162
|
+
# - +target+ The target of the write, which may be a string containing the path or a stream instance that supports write
|
163
|
+
# - +contents+ The contents to be write, which may be a +Hash+, or an +Array+, or a +String+ containing delimited fields
|
164
|
+
# - +options+ An options hash, containing any of the following options
|
132
165
|
#
|
133
166
|
# * *Options:*
|
134
|
-
# - +:column_separator
|
135
|
-
# - +:eol_lookahead_limit
|
136
|
-
# - +:line_separator
|
167
|
+
# - +:column_separator+ {optional} The column separator, to be applied between each field in the case where +contents+ is a +Hash+.
|
168
|
+
# - +:eol_lookahead_limit+ {optional} The number of content elements (line/pair) to inspect to determine whether element has a terminating end-of-line sequence. Defaults to 20. If 0, and +:line_separator+ is not specified, then will default to <tt>"\n"</tt>. If +nil+, then every line will be inspected.
|
169
|
+
# - +:line_separator+ {optional} The line separator, to be applied to the end of line created from each entry. When not specified, it will be deduced by inspecting +contents+ (according to +eol_lookahead_limit+).
|
170
|
+
# - +:no_last_eol+ {optional} If present and _truey_, causes suppression of the addition of the +:line_separator+ on the last line.
|
137
171
|
#
|
138
172
|
# === Return
|
139
173
|
#
|
@@ -165,6 +199,7 @@ $stderr.puts "#{self.class}.write_to_target_(target(#{target.class})='#{target}'
|
|
165
199
|
options ||= {}
|
166
200
|
eol_lookahead_limit = options[:eol_lookahead_limit] || WriteLine_Constants_::NUMBER_OF_LINES_TO_EXAMINE
|
167
201
|
column_separator = options[:column_separator] || ''
|
202
|
+
no_last_eol = options[:no_last_eol] || false
|
168
203
|
line_separator = nil
|
169
204
|
line_separator ||= options[:line_separator]
|
170
205
|
line_separator ||= self.deduce_line_separator_(contents, eol_lookahead_limit) unless !eol_lookahead_limit.kind_of?(::Integer) || 0 == eol_lookahead_limit
|
@@ -181,11 +216,11 @@ $stderr.puts "#{self.class}.write_to_target_(target(#{target.class})='#{target}'
|
|
181
216
|
|
182
217
|
File.open(target, "w") do |io|
|
183
218
|
|
184
|
-
self.write_to_target_ io, contents, line_separator, column_separator
|
219
|
+
self.write_to_target_ io, contents, line_separator, column_separator, no_last_eol
|
185
220
|
end
|
186
221
|
else
|
187
222
|
|
188
|
-
self.write_to_target_ target, contents, line_separator, column_separator
|
223
|
+
self.write_to_target_ target, contents, line_separator, column_separator, no_last_eol
|
189
224
|
end
|
190
225
|
end # writelines
|
191
226
|
end # module IO
|
@@ -193,3 +228,4 @@ end # module Xqsr3
|
|
193
228
|
|
194
229
|
# ############################## end of file ############################# #
|
195
230
|
|
231
|
+
|
data/lib/xqsr3/quality.rb
CHANGED
@@ -5,13 +5,13 @@
|
|
5
5
|
# Purpose: Definition of the ParameterChecking module
|
6
6
|
#
|
7
7
|
# Created: 12th February 2015
|
8
|
-
# Updated:
|
8
|
+
# Updated: 15th April 2019
|
9
9
|
#
|
10
10
|
# Home: http://github.com/synesissoftware/xqsr3
|
11
11
|
#
|
12
12
|
# Author: Matthew Wilson
|
13
13
|
#
|
14
|
-
# Copyright (c) 2015-
|
14
|
+
# Copyright (c) 2015-2019, Matthew Wilson and Synesis Software
|
15
15
|
# All rights reserved.
|
16
16
|
#
|
17
17
|
# Redistribution and use in source and binary forms, with or without
|
@@ -59,7 +59,8 @@ module Quality
|
|
59
59
|
module ParameterChecking
|
60
60
|
|
61
61
|
private
|
62
|
-
|
62
|
+
# @!visibility private
|
63
|
+
module Util_ # :nodoc: all
|
63
64
|
|
64
65
|
def self.join_with_or a
|
65
66
|
|
@@ -76,7 +77,7 @@ module ParameterChecking
|
|
76
77
|
end
|
77
78
|
end
|
78
79
|
|
79
|
-
module Constants
|
80
|
+
module Constants # :nodoc:
|
80
81
|
|
81
82
|
RECOGNISED_OPTION_NAMES = %w{
|
82
83
|
|
@@ -99,7 +100,7 @@ module ParameterChecking
|
|
99
100
|
end # module Util_
|
100
101
|
public
|
101
102
|
|
102
|
-
def self.included base
|
103
|
+
def self.included base # :nodoc:
|
103
104
|
|
104
105
|
base.extend self
|
105
106
|
end
|
@@ -107,42 +108,27 @@ module ParameterChecking
|
|
107
108
|
private
|
108
109
|
# Check a given parameter (value=+value+, name=+name+) for type and value
|
109
110
|
#
|
110
|
-
#
|
111
|
-
# @param +name+:: (::String, ::Symbol) the name of the parameter to be
|
112
|
-
# checked
|
113
|
-
# @param +options+:: (::Hash) options that moderate the behaviour
|
111
|
+
# === Signature
|
114
112
|
#
|
115
|
-
#
|
116
|
-
#
|
117
|
-
#
|
118
|
-
#
|
119
|
-
#
|
120
|
-
#
|
121
|
-
#
|
122
|
-
#
|
123
|
-
#
|
124
|
-
#
|
125
|
-
#
|
126
|
-
#
|
127
|
-
#
|
128
|
-
#
|
129
|
-
#
|
130
|
-
#
|
131
|
-
#
|
132
|
-
#
|
133
|
-
#
|
134
|
-
# +empty?+ message and to do so with true, unless +nil+
|
135
|
-
# @option +:nothrow+:: (boolean) causes failure to be indicated by a
|
136
|
-
# +nil+ return rather than a thrown exception
|
137
|
-
# @option +:message+:: (::String) specifies a message to be used in any
|
138
|
-
# thrown exception, which suppresses internal message
|
139
|
-
# preparation
|
140
|
-
# @option +:strip_str_whitespace+:: (boolean) If +value+ is a string (as
|
141
|
-
# determined by responding to +to_str+ message), then it will
|
142
|
-
# be stripped - leading and trailing whitespace removed -
|
143
|
-
# before any processing
|
144
|
-
# @option +:treat_as_option+:: (boolean) If true, the value will be
|
145
|
-
# treated as an option when reporting check failure
|
113
|
+
# * *Parameters:*
|
114
|
+
# - +value+ the parameter whose value and type is to be checked
|
115
|
+
# - +name+ (::String, ::Symbol) the name of the parameter to be checked
|
116
|
+
# - +options+ (::Hash) options that moderate the behaviour
|
117
|
+
#
|
118
|
+
# * *Options:*
|
119
|
+
# - +:allow_nil+ (boolean) The +value+ must not be +nil+ unless this option is true
|
120
|
+
# - +:nil+ an alias for +:allow_nil+
|
121
|
+
# - +:ignore_case+ (boolean) When +:values+ is specified, comparisons of strings, or arrays of strings, will be carried out in a case-insensitive manner
|
122
|
+
# - +: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
|
123
|
+
# - +:type+ (::Class) A single type parameter, used only if +:types+ is not specified
|
124
|
+
# - +:values+ (::Array) an array of values one of which +value+ must be
|
125
|
+
# - +:responds_to+ (::Array) An array of symbols specifying all messages to which the parameter will respond
|
126
|
+
# - +:reject_empty+ (boolean) requires value to respond to +empty?+ message and to do so with false, unless +nil+
|
127
|
+
# - +:require_empty+ (boolean) requires value to respond to +empty?+ message and to do so with true, unless +nil+
|
128
|
+
# - +:nothrow+ (boolean) causes failure to be indicated by a +nil+ return rather than a thrown exception
|
129
|
+
# - +:message+ (::String) specifies a message to be used in any thrown exception, which suppresses internal message preparation
|
130
|
+
# - +:strip_str_whitespace+ (boolean) If +value+ is a string (as determined by responding to +to_str+ message), then it will be stripped - leading and trailing whitespace removed - before any processing
|
131
|
+
# - +:treat_as_option+ (boolean) If true, the value will be treated as an option when reporting check failure
|
146
132
|
#
|
147
133
|
# This method is private, because it should only be used within methods
|
148
134
|
def check_parameter value, name, options = {}, &block
|
@@ -162,15 +148,14 @@ module ParameterChecking
|
|
162
148
|
# Specific form of the +check_parameter()+ that is used to check
|
163
149
|
# options, taking instead the hash and the key
|
164
150
|
#
|
165
|
-
#
|
166
|
-
#
|
167
|
-
#
|
168
|
-
#
|
169
|
-
#
|
170
|
-
#
|
171
|
-
# +:treat_as_option+ option (with the value +true+) is merged in
|
172
|
-
# before calling +check_parameter()+
|
151
|
+
# === Signature
|
152
|
+
#
|
153
|
+
# * *Parameters:*
|
154
|
+
# - +h+ (::Hash) The options hash from which the named element is to be tested. May not be +nil+
|
155
|
+
# - +name+ (::String, ::Symbol, [ ::String, ::Symbol ]) The options key name, or an array of names. May not be +nil+
|
156
|
+
# - +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()+
|
173
157
|
#
|
158
|
+
# * *Options:*
|
174
159
|
def check_option h, name, options = {}, &block
|
175
160
|
|
176
161
|
Util_.check_option h, name, options, &block
|
@@ -179,37 +164,26 @@ module ParameterChecking
|
|
179
164
|
public
|
180
165
|
# Check a given parameter (value=+value+, name=+name+) for type and value
|
181
166
|
#
|
182
|
-
#
|
183
|
-
#
|
184
|
-
#
|
167
|
+
# === Signature
|
168
|
+
#
|
169
|
+
# * *Parameters:*
|
170
|
+
# - +value+ the parameter whose value and type is to be checked
|
171
|
+
# - +name+ the name of the parameter to be checked
|
172
|
+
# - +options+ options
|
185
173
|
#
|
186
|
-
#
|
187
|
-
#
|
188
|
-
#
|
189
|
-
#
|
190
|
-
#
|
191
|
-
#
|
192
|
-
#
|
193
|
-
#
|
194
|
-
#
|
195
|
-
#
|
196
|
-
#
|
197
|
-
#
|
198
|
-
#
|
199
|
-
# must be
|
200
|
-
# @option +:responds_to+:: (::Array) An array of symbols specifying all
|
201
|
-
# messages to which the parameter will respond
|
202
|
-
# @option +:reject_empty+:: (boolean) requires value to respond to +empty?+
|
203
|
-
# message and to do so with false, unless +nil+
|
204
|
-
# @option +:require_empty+:: (boolean) requires value to respond to
|
205
|
-
# +empty?+ message and to do so with true, unless +nil+
|
206
|
-
# @option +:nothrow+:: (boolean) causes failure to be indicated by a +nil+
|
207
|
-
# return rather than a thrown exception
|
208
|
-
# @option +:message+:: (boolean) specifies a message to be used in any
|
209
|
-
# thrown exception, which suppresses internal message
|
210
|
-
# preparation
|
211
|
-
# @option +:treat_as_option+:: (boolean) If true, the value will be
|
212
|
-
# treated as an option when reporting check failure
|
174
|
+
# * *Options:*
|
175
|
+
# - +:allow_nil+ (boolean) The +value+ must not be +nil+ unless this option is true
|
176
|
+
# - +:nil+ an alias for +:allow_nil+
|
177
|
+
# - +:ignore_case+ (boolean) When +:values+ is specified, comparisons of strings, or arrays of strings, will be carried out in a case-insensitive manner
|
178
|
+
# - +: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
|
179
|
+
# - +:type+ (::Class) A single type parameter, used only if +:types+ is not specified
|
180
|
+
# - +:values+ (::Array) an array of values one of which +value+ must be
|
181
|
+
# - +:responds_to+ (::Array) An array of symbols specifying all messages to which the parameter will respond
|
182
|
+
# - +:reject_empty+ (boolean) requires value to respond to +empty?+ message and to do so with false, unless +nil+
|
183
|
+
# - +:require_empty+ (boolean) requires value to respond to +empty?+ message and to do so with true, unless +nil+
|
184
|
+
# - +:nothrow+ (boolean) causes failure to be indicated by a +nil+ return rather than a thrown exception
|
185
|
+
# - +:message+ (boolean) specifies a message to be used in any thrown exception, which suppresses internal message preparation
|
186
|
+
# - +:treat_as_option+ (boolean) If true, the value will be treated as an option when reporting check failure
|
213
187
|
#
|
214
188
|
def self.check_parameter value, name, options = {}, &block
|
215
189
|
|