Class: DSLCompose::DSL::Arguments::Argument
- Inherits:
-
Object
- Object
- DSLCompose::DSL::Arguments::Argument
- Defined in:
- lib/dsl_compose/dsl/arguments/argument.rb,
lib/dsl_compose/dsl/arguments/argument/interpreter.rb,
lib/dsl_compose/dsl/arguments/argument/in_validation.rb,
lib/dsl_compose/dsl/arguments/argument/is_a_validation.rb,
lib/dsl_compose/dsl/arguments/argument/format_validation.rb,
lib/dsl_compose/dsl/arguments/argument/length_validation.rb,
lib/dsl_compose/dsl/arguments/argument/not_in_validation.rb,
lib/dsl_compose/dsl/arguments/argument/end_with_validation.rb,
lib/dsl_compose/dsl/arguments/argument/equal_to_validation.rb,
lib/dsl_compose/dsl/arguments/argument/less_than_validation.rb,
lib/dsl_compose/dsl/arguments/argument/start_with_validation.rb,
lib/dsl_compose/dsl/arguments/argument/greater_than_validation.rb,
lib/dsl_compose/dsl/arguments/argument/not_end_with_validation.rb,
lib/dsl_compose/dsl/arguments/argument/not_start_with_validation.rb,
lib/dsl_compose/dsl/arguments/argument/less_than_or_equal_to_validation.rb,
lib/dsl_compose/dsl/arguments/argument/greater_than_or_equal_to_validation.rb
Defined Under Namespace
Classes: ArgumentNameReservedError, DescriptionAlreadyExistsError, EndWithValidation, EqualToValidation, FormatValidation, GreaterThanOrEqualToValidation, GreaterThanValidation, ImpossibleKwargError, InValidation, Interpreter, InvalidDescriptionError, InvalidNameError, InvalidTypeError, IsAValidation, LengthValidation, LessThanOrEqualToValidation, LessThanValidation, NotEndWithValidation, NotInValidation, NotStartWithValidation, StartWithValidation, ValidationAlreadyExistsError, ValidationIncompatibleError, ValidationInvalidArgumentError
Constant Summary collapse
- RESERVED_ARGUMENT_NAMES =
[ :child_class, :dsl_name, :method_name ].freeze
Instance Attribute Summary collapse
-
#array ⇒ Object
readonly
If true, then this argument accepts an array of values.
-
#default ⇒ Object
readonly
The default value for optional arguments, if one is not provided then nil will be assumed.
-
#description ⇒ Object
readonly
An otional description of this Attribute, if provided then it must be a string.
-
#end_with_validation ⇒ Object
readonly
Returns the value of attribute end_with_validation.
-
#equal_to_validation ⇒ Object
readonly
Returns the value of attribute equal_to_validation.
-
#format_validation ⇒ Object
readonly
Returns the value of attribute format_validation.
-
#greater_than_or_equal_to_validation ⇒ Object
readonly
Returns the value of attribute greater_than_or_equal_to_validation.
-
#greater_than_validation ⇒ Object
readonly
Optional validations that have been applied to this Argument.
-
#in_validation ⇒ Object
readonly
Returns the value of attribute in_validation.
-
#is_a_validation ⇒ Object
readonly
Returns the value of attribute is_a_validation.
-
#kwarg ⇒ Object
readonly
If true, then this argument must be provided as a keyword argument, this is only appropriate for required arguments, as optional arguments are always passed as keywork arguments.
-
#length_validation ⇒ Object
readonly
Returns the value of attribute length_validation.
-
#less_than_or_equal_to_validation ⇒ Object
readonly
Returns the value of attribute less_than_or_equal_to_validation.
-
#less_than_validation ⇒ Object
readonly
Returns the value of attribute less_than_validation.
-
#name ⇒ Object
readonly
The name of this Argument.
-
#not_end_with_validation ⇒ Object
readonly
Returns the value of attribute not_end_with_validation.
-
#not_in_validation ⇒ Object
readonly
Returns the value of attribute not_in_validation.
-
#not_start_with_validation ⇒ Object
readonly
Returns the value of attribute not_start_with_validation.
-
#required ⇒ Object
readonly
if required, then this Argument must be provided when calling its associated DSLMethod.
-
#start_with_validation ⇒ Object
readonly
Returns the value of attribute start_with_validation.
-
#type ⇒ Object
readonly
An arguments type.
Instance Method Summary collapse
-
#has_description? ⇒ Boolean
Returns ‘true` if this DSL has a description, else false.
-
#initialize(name, required, kwarg, type, array: false, default: nil, &block) ⇒ Argument
constructor
Create a new Attribute object.
-
#optional? ⇒ Boolean
returns true if this DSLMethod is flagged as optional, otherwise returns false.
-
#required? ⇒ Boolean
returns true if this DSLMethod is flagged as required, otherwise returns false.
-
#set_description(description) ⇒ Object
Set the description for this Argument to the provided value.
-
#validate_boolean!(value) ⇒ Object
returns true if every provided boolean validation also returns true.
-
#validate_class!(value) ⇒ Object
returns true if every provided class validation also returns true.
- #validate_end_with(value) ⇒ Object
- #validate_equal_to(value) ⇒ Object
-
#validate_float!(value) ⇒ Object
returns true if every provided float validation also returns true.
- #validate_format(regexp) ⇒ Object
- #validate_greater_than(value) ⇒ Object
- #validate_greater_than_or_equal_to(value) ⇒ Object
- #validate_in(values) ⇒ Object
-
#validate_integer!(value) ⇒ Object
returns true if every provided integer validation also returns true.
- #validate_is_a(klass) ⇒ Object
- #validate_length(maximum: nil, minimum: nil, is: nil) ⇒ Object
- #validate_less_than(value) ⇒ Object
- #validate_less_than_or_equal_to(value) ⇒ Object
- #validate_not_end_with(value) ⇒ Object
- #validate_not_in(values) ⇒ Object
- #validate_not_start_with(value) ⇒ Object
-
#validate_object!(value) ⇒ Object
returns true if every provided object validation also returns true.
- #validate_start_with(value) ⇒ Object
-
#validate_string!(value) ⇒ Object
returns true if every provided string validation also returns true.
-
#validate_symbol!(value) ⇒ Object
returns true if every provided symbol validation also returns true.
Constructor Details
#initialize(name, required, kwarg, type, array: false, default: nil, &block) ⇒ Argument
Create a new Attribute object.
‘name` must be a symbol. `required` is a boolean which determines if this Attribute must be provided when calling its associated DSLMethod. `kwarg` is a boolean which determines if a required Attribute must be provided as a keyword argument. `type` can be either :integer, :boolean, :float, :string or :symbol `block` contains the instructions to further configure this Attribute
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/dsl_compose/dsl/arguments/argument.rb', line 86 def initialize name, required, kwarg, type, array: false, default: nil, &block if name.is_a? Symbol if RESERVED_ARGUMENT_NAMES.include? name raise ArgumentNameReservedError, "This argument name `#{name}` is a reserved word. The names #{RESERVED_ARGUMENT_NAMES.join ", "} can not be used here because the Parser uses them to express a structural part of the DSL" end @name = name else raise InvalidNameError, "The option name `#{name}` is invalid, it must be of type symbol." end if type == :integer || type == :boolean || type == :float || type == :string || type == :symbol || type == :class || type == :object @type = type else raise InvalidTypeError, "Argument type `#{type}` must be one of :integer, :boolean, :float, :string, :symbol, :class or :object" end @required = required ? true : false if @required == false && kwarg == true raise ImpossibleKwargError, "Optional arguments must always be provided as keyword arguments. The argument `#{name}` can not be both required: false and kwarg: true." end @kwarg = kwarg ? true : false @array = array ? true : false unless default.nil? if @required raise ImpossibleKwargError, "The argument `#{name}` is required, so can not be given a default value." end @default = default end # If a block was provided, then we evaluate it using a seperate # interpreter class. We do this because the interpreter class contains # no other methods or variables, if it was evaluated in the context of # this class then the block would have access to all of the methods defined # in here. if block Interpreter.new(self).instance_eval(&block) end rescue => e raise e, "Error while defining argument #{name}\n#{e.}", e.backtrace end |
Instance Attribute Details
#array ⇒ Object (readonly)
If true, then this argument accepts an array of values. It will also accept a single value, but that single value will be automatically converted to an array
54 55 56 |
# File 'lib/dsl_compose/dsl/arguments/argument.rb', line 54 def array @array end |
#default ⇒ Object (readonly)
The default value for optional arguments, if one is not provided then nil will be assumed.
56 57 58 |
# File 'lib/dsl_compose/dsl/arguments/argument.rb', line 56 def default @default end |
#description ⇒ Object (readonly)
An otional description of this Attribute, if provided then it must be a string. The description accepts markdown and is used when generating documentation.
59 60 61 |
# File 'lib/dsl_compose/dsl/arguments/argument.rb', line 59 def description @description end |
#end_with_validation ⇒ Object (readonly)
Returns the value of attribute end_with_validation.
71 72 73 |
# File 'lib/dsl_compose/dsl/arguments/argument.rb', line 71 def end_with_validation @end_with_validation end |
#equal_to_validation ⇒ Object (readonly)
Returns the value of attribute equal_to_validation.
68 69 70 |
# File 'lib/dsl_compose/dsl/arguments/argument.rb', line 68 def equal_to_validation @equal_to_validation end |
#format_validation ⇒ Object (readonly)
Returns the value of attribute format_validation.
67 68 69 |
# File 'lib/dsl_compose/dsl/arguments/argument.rb', line 67 def format_validation @format_validation end |
#greater_than_or_equal_to_validation ⇒ Object (readonly)
Returns the value of attribute greater_than_or_equal_to_validation.
64 65 66 |
# File 'lib/dsl_compose/dsl/arguments/argument.rb', line 64 def greater_than_or_equal_to_validation @greater_than_or_equal_to_validation end |
#greater_than_validation ⇒ Object (readonly)
Optional validations that have been applied to this Argument. When the DSL is used each of these validations will be checked against the value provided to this Argument.
63 64 65 |
# File 'lib/dsl_compose/dsl/arguments/argument.rb', line 63 def greater_than_validation @greater_than_validation end |
#in_validation ⇒ Object (readonly)
Returns the value of attribute in_validation.
69 70 71 |
# File 'lib/dsl_compose/dsl/arguments/argument.rb', line 69 def in_validation @in_validation end |
#is_a_validation ⇒ Object (readonly)
Returns the value of attribute is_a_validation.
76 77 78 |
# File 'lib/dsl_compose/dsl/arguments/argument.rb', line 76 def is_a_validation @is_a_validation end |
#kwarg ⇒ Object (readonly)
If true, then this argument must be provided as a keyword argument, this is only appropriate for required arguments, as optional arguments are always passed as keywork arguments. arguments.
51 52 53 |
# File 'lib/dsl_compose/dsl/arguments/argument.rb', line 51 def kwarg @kwarg end |
#length_validation ⇒ Object (readonly)
Returns the value of attribute length_validation.
75 76 77 |
# File 'lib/dsl_compose/dsl/arguments/argument.rb', line 75 def length_validation @length_validation end |
#less_than_or_equal_to_validation ⇒ Object (readonly)
Returns the value of attribute less_than_or_equal_to_validation.
66 67 68 |
# File 'lib/dsl_compose/dsl/arguments/argument.rb', line 66 def less_than_or_equal_to_validation @less_than_or_equal_to_validation end |
#less_than_validation ⇒ Object (readonly)
Returns the value of attribute less_than_validation.
65 66 67 |
# File 'lib/dsl_compose/dsl/arguments/argument.rb', line 65 def less_than_validation @less_than_validation end |
#name ⇒ Object (readonly)
The name of this Argument.
41 42 43 |
# File 'lib/dsl_compose/dsl/arguments/argument.rb', line 41 def name @name end |
#not_end_with_validation ⇒ Object (readonly)
Returns the value of attribute not_end_with_validation.
72 73 74 |
# File 'lib/dsl_compose/dsl/arguments/argument.rb', line 72 def not_end_with_validation @not_end_with_validation end |
#not_in_validation ⇒ Object (readonly)
Returns the value of attribute not_in_validation.
70 71 72 |
# File 'lib/dsl_compose/dsl/arguments/argument.rb', line 70 def not_in_validation @not_in_validation end |
#not_start_with_validation ⇒ Object (readonly)
Returns the value of attribute not_start_with_validation.
74 75 76 |
# File 'lib/dsl_compose/dsl/arguments/argument.rb', line 74 def not_start_with_validation @not_start_with_validation end |
#required ⇒ Object (readonly)
if required, then this Argument must be provided when calling its associated DSLMethod.
47 48 49 |
# File 'lib/dsl_compose/dsl/arguments/argument.rb', line 47 def required @required end |
#start_with_validation ⇒ Object (readonly)
Returns the value of attribute start_with_validation.
73 74 75 |
# File 'lib/dsl_compose/dsl/arguments/argument.rb', line 73 def start_with_validation @start_with_validation end |
#type ⇒ Object (readonly)
An arguments type. This determines what kind of value can be passed when calling the associated DSLMethod. ‘type` should be set to either :integer, :boolean, :float, :string or :symbol
45 46 47 |
# File 'lib/dsl_compose/dsl/arguments/argument.rb', line 45 def type @type end |
Instance Method Details
#has_description? ⇒ Boolean
Returns ‘true` if this DSL has a description, else false.
150 151 152 |
# File 'lib/dsl_compose/dsl/arguments/argument.rb', line 150 def has_description? @description.nil? == false end |
#optional? ⇒ Boolean
returns true if this DSLMethod is flagged as optional, otherwise returns false.
160 161 162 |
# File 'lib/dsl_compose/dsl/arguments/argument.rb', line 160 def optional? @required == false end |
#required? ⇒ Boolean
returns true if this DSLMethod is flagged as required, otherwise returns false.
155 156 157 |
# File 'lib/dsl_compose/dsl/arguments/argument.rb', line 155 def required? @required == true end |
#set_description(description) ⇒ Object
Set the description for this Argument to the provided value.
‘description` must be a string with a length greater than 0. The `description` can only be set once per Argument
137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/dsl_compose/dsl/arguments/argument.rb', line 137 def set_description description unless description.is_a?(String) && description.strip.length > 0 raise InvalidDescriptionError, "The option description `#{description}` is invalid, it must be of type string and have length greater than 0." end if has_description? raise DescriptionAlreadyExistsError, "The description has already been set" end @description = description.strip end |
#validate_boolean!(value) ⇒ Object
returns true if every provided boolean validation also returns true
439 440 441 |
# File 'lib/dsl_compose/dsl/arguments/argument.rb', line 439 def validate_boolean! value (equal_to_validation.nil? || equal_to_validation.validate!(value)) end |
#validate_class!(value) ⇒ Object
returns true if every provided class validation also returns true
444 445 446 447 448 449 450 |
# File 'lib/dsl_compose/dsl/arguments/argument.rb', line 444 def validate_class! value (format_validation.nil? || format_validation.validate!(value.class_name)) && (end_with_validation.nil? || end_with_validation.validate!(value.class_name)) && (not_end_with_validation.nil? || not_end_with_validation.validate!(value.class_name)) && (start_with_validation.nil? || start_with_validation.validate!(value.class_name)) && (not_start_with_validation.nil? || not_start_with_validation.validate!(value.class_name)) end |
#validate_end_with(value) ⇒ Object
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 |
# File 'lib/dsl_compose/dsl/arguments/argument.rb', line 289 def validate_end_with value valid_type = value.is_a?(Symbol) || value.is_a?(String) valid_array_of_symbols = (value.is_a?(Array) && value.all? { |value| value.is_a? Symbol }) valid_array_of_strings = (value.is_a?(Array) && value.all? { |value| value.is_a? String }) unless valid_type || valid_array_of_symbols || valid_array_of_strings raise ValidationInvalidArgumentError, "The value `#{value}` provided to this validator must be a Symbol/String or an Array of Symbols/Strings" end unless @type == :string || @type == :symbol || @type == :class raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type" end # if this validation has already been applied, then add the values to the existing validation if @end_with_validation @end_with_validation.add_values value else @end_with_validation = EndWithValidation.new value end end |
#validate_equal_to(value) ⇒ Object
243 244 245 246 247 248 249 250 251 252 253 |
# File 'lib/dsl_compose/dsl/arguments/argument.rb', line 243 def validate_equal_to value if @equal_to_validation raise ValidationAlreadyExistsError, "The validation `equal_to` has already been applied to this method option." end unless @type == :integer || @type == :float || @type == :string || @type == :symbol || @type == :boolean raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type" end @equal_to_validation = EqualToValidation.new value end |
#validate_float!(value) ⇒ Object
returns true if every provided float validation also returns true
407 408 409 410 |
# File 'lib/dsl_compose/dsl/arguments/argument.rb', line 407 def validate_float! value # floats are validated with the same set of validators as integers validate_integer! value end |
#validate_format(regexp) ⇒ Object
228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/dsl_compose/dsl/arguments/argument.rb', line 228 def validate_format regexp if @format_validation raise ValidationAlreadyExistsError, "The validation `format` has already been applied to this method option." end unless regexp.is_a? Regexp raise ValidationInvalidArgumentError, regexp end unless @type == :string || @type == :symbol || @type == :class raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type" end @format_validation = FormatValidation.new regexp end |
#validate_greater_than(value) ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/dsl_compose/dsl/arguments/argument.rb', line 164 def validate_greater_than value if @greater_than_validation raise ValidationAlreadyExistsError, "The validation `greater_than` has already been applied to this method option." end unless value.is_a?(Numeric) raise ValidationInvalidArgumentError, value end unless @type == :integer || @type == :float raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type" end @greater_than_validation = GreaterThanValidation.new value end |
#validate_greater_than_or_equal_to(value) ⇒ Object
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/dsl_compose/dsl/arguments/argument.rb', line 180 def validate_greater_than_or_equal_to value if @greater_than_or_equal_to_validation raise ValidationAlreadyExistsError, "The validation `greater_than_or_equal_to` has already been applied to this method option." end unless value.is_a?(Numeric) raise ValidationInvalidArgumentError, value end unless @type == :integer || @type == :float raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type" end @greater_than_or_equal_to_validation = GreaterThanOrEqualToValidation.new value end |
#validate_in(values) ⇒ Object
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/dsl_compose/dsl/arguments/argument.rb', line 255 def validate_in values unless values.is_a? Array raise ValidationInvalidArgumentError, values end unless @type == :integer || @type == :float || @type == :string || @type == :symbol raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type" end # if this validation has already been applied, then add the values to the existing validation if @in_validation @in_validation.add_values values else @in_validation = InValidation.new values end end |
#validate_integer!(value) ⇒ Object
returns true if every provided integer validation also returns true
394 395 396 397 398 399 400 401 402 403 404 |
# File 'lib/dsl_compose/dsl/arguments/argument.rb', line 394 def validate_integer! value (greater_than_validation.nil? || greater_than_validation.validate!(value)) && (greater_than_or_equal_to_validation.nil? || greater_than_or_equal_to_validation.validate!(value)) && (less_than_validation.nil? || less_than_validation.validate!(value)) && (less_than_or_equal_to_validation.nil? || less_than_or_equal_to_validation.validate!(value)) && (format_validation.nil? || format_validation.validate!(value)) && (equal_to_validation.nil? || equal_to_validation.validate!(value)) && (in_validation.nil? || in_validation.validate!(value)) && (not_in_validation.nil? || not_in_validation.validate!(value)) && (length_validation.nil? || length_validation.validate!(value)) end |
#validate_is_a(klass) ⇒ Object
381 382 383 384 385 386 387 388 389 390 391 |
# File 'lib/dsl_compose/dsl/arguments/argument.rb', line 381 def validate_is_a klass if @is_a_validation raise ValidationAlreadyExistsError, "The validation `is_a` has already been applied to this method option." end unless @type == :object raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type" end @is_a_validation = IsAValidation.new(klass) end |
#validate_length(maximum: nil, minimum: nil, is: nil) ⇒ Object
369 370 371 372 373 374 375 376 377 378 379 |
# File 'lib/dsl_compose/dsl/arguments/argument.rb', line 369 def validate_length maximum: nil, minimum: nil, is: nil if @length_validation raise ValidationAlreadyExistsError, "The validation `length` has already been applied to this method option." end unless @type == :string || @type == :symbol raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type" end @length_validation = LengthValidation.new(maximum: maximum, minimum: minimum, is: is) end |
#validate_less_than(value) ⇒ Object
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/dsl_compose/dsl/arguments/argument.rb', line 196 def validate_less_than value if @less_than_validation raise ValidationAlreadyExistsError, "The validation `less_than` has already been applied to this method option." end unless value.is_a?(Numeric) raise ValidationInvalidArgumentError, value end unless @type == :integer || @type == :float raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type" end @less_than_validation = LessThanValidation.new value end |
#validate_less_than_or_equal_to(value) ⇒ Object
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/dsl_compose/dsl/arguments/argument.rb', line 212 def validate_less_than_or_equal_to value if @less_than_or_equal_to_validation raise ValidationAlreadyExistsError, "The validation `less_than_or_equal_to` has already been applied to this method option." end unless value.is_a?(Numeric) raise ValidationInvalidArgumentError, value end unless @type == :integer || @type == :float raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type" end @less_than_or_equal_to_validation = LessThanOrEqualToValidation.new value end |
#validate_not_end_with(value) ⇒ Object
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 |
# File 'lib/dsl_compose/dsl/arguments/argument.rb', line 309 def validate_not_end_with value valid_type = value.is_a?(Symbol) || value.is_a?(String) valid_array_of_symbols = (value.is_a?(Array) && value.all? { |value| value.is_a? Symbol }) valid_array_of_strings = (value.is_a?(Array) && value.all? { |value| value.is_a? String }) unless valid_type || valid_array_of_symbols || valid_array_of_strings raise ValidationInvalidArgumentError, "The value `#{value}` provided to this validator must be a Symbol/String or an Array of Symbols/Strings" end unless @type == :string || @type == :symbol || @type == :class raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type" end # if this validation has already been applied, then add the values to the existing validation if @not_end_with_validation @not_end_with_validation.add_values value else @not_end_with_validation = NotEndWithValidation.new value end end |
#validate_not_in(values) ⇒ Object
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'lib/dsl_compose/dsl/arguments/argument.rb', line 272 def validate_not_in values unless values.is_a? Array raise ValidationInvalidArgumentError, values end unless @type == :integer || @type == :float || @type == :string || @type == :symbol raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type" end # if this validation has already been applied, then add the values to the existing validation if @not_in_validation @not_in_validation.add_values values else @not_in_validation = NotInValidation.new values end end |
#validate_not_start_with(value) ⇒ Object
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 |
# File 'lib/dsl_compose/dsl/arguments/argument.rb', line 349 def validate_not_start_with value valid_type = value.is_a?(Symbol) || value.is_a?(String) valid_array_of_symbols = (value.is_a?(Array) && value.all? { |value| value.is_a? Symbol }) valid_array_of_strings = (value.is_a?(Array) && value.all? { |value| value.is_a? String }) unless valid_type || valid_array_of_symbols || valid_array_of_strings raise ValidationInvalidArgumentError, "The value `#{value}` provided to this validator must be a Symbol/String or an Array of Symbols/Strings" end unless @type == :string || @type == :symbol || @type == :class raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type" end # if this validation has already been applied, then add the values to the existing validation if @not_start_with_validation @not_start_with_validation.add_values value else @not_start_with_validation = NotStartWithValidation.new value end end |
#validate_object!(value) ⇒ Object
returns true if every provided object validation also returns true
453 454 455 |
# File 'lib/dsl_compose/dsl/arguments/argument.rb', line 453 def validate_object! value (is_a_validation.nil? || is_a_validation.validate!(value)) end |
#validate_start_with(value) ⇒ Object
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 |
# File 'lib/dsl_compose/dsl/arguments/argument.rb', line 329 def validate_start_with value valid_type = value.is_a?(Symbol) || value.is_a?(String) valid_array_of_symbols = (value.is_a?(Array) && value.all? { |value| value.is_a? Symbol }) valid_array_of_strings = (value.is_a?(Array) && value.all? { |value| value.is_a? String }) unless valid_type || valid_array_of_symbols || valid_array_of_strings raise ValidationInvalidArgumentError, "The value `#{value}` provided to this validator must be a Symbol/String or an Array of Symbols/Strings" end unless @type == :string || @type == :symbol || @type == :class raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type" end # if this validation has already been applied, then add the values to the existing validation if @start_with_validation @start_with_validation.add_values value else @start_with_validation = StartWithValidation.new value end end |
#validate_string!(value) ⇒ Object
returns true if every provided string validation also returns true
426 427 428 429 430 431 432 433 434 435 436 |
# File 'lib/dsl_compose/dsl/arguments/argument.rb', line 426 def validate_string! value (format_validation.nil? || format_validation.validate!(value)) && (equal_to_validation.nil? || equal_to_validation.validate!(value)) && (in_validation.nil? || in_validation.validate!(value)) && (not_in_validation.nil? || not_in_validation.validate!(value)) && (end_with_validation.nil? || end_with_validation.validate!(value)) && (not_end_with_validation.nil? || not_end_with_validation.validate!(value)) && (start_with_validation.nil? || start_with_validation.validate!(value)) && (not_start_with_validation.nil? || not_start_with_validation.validate!(value)) && (length_validation.nil? || length_validation.validate!(value)) end |
#validate_symbol!(value) ⇒ Object
returns true if every provided symbol validation also returns true
413 414 415 416 417 418 419 420 421 422 423 |
# File 'lib/dsl_compose/dsl/arguments/argument.rb', line 413 def validate_symbol! value (format_validation.nil? || format_validation.validate!(value)) && (equal_to_validation.nil? || equal_to_validation.validate!(value)) && (in_validation.nil? || in_validation.validate!(value)) && (not_in_validation.nil? || not_in_validation.validate!(value)) && (end_with_validation.nil? || end_with_validation.validate!(value)) && (not_end_with_validation.nil? || not_end_with_validation.validate!(value)) && (start_with_validation.nil? || start_with_validation.validate!(value)) && (not_start_with_validation.nil? || not_start_with_validation.validate!(value)) && (length_validation.nil? || length_validation.validate!(value)) end |