Module: Cuprum::ParameterValidation::ClassMethods
- Defined in:
- lib/cuprum/parameter_validation.rb
Overview
Class methods for parameter validation.
Instance Method Summary collapse
- #each_validation ⇒ Object
- #validate(name, type = nil, using: nil, **options) ⇒ Object
- #validate_parameters(command) ⇒ Object
Instance Method Details
#each_validation ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/cuprum/parameter_validation.rb', line 19 def each_validation(&) return enum_for(:each_validation) unless block_given? ancestors.reverse_each do |ancestor| next unless ancestor.respond_to?(:validation_rules, true) ancestor.validation_rules.each(&) end end |
#validate(name, **options) ⇒ Object #validate(name, using: , **options) ⇒ Object #validate(name, **options) {|value| ... } ⇒ Object #validate(name, type, **options) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/cuprum/parameter_validation.rb', line 113 def validate(name, type = nil, using: nil, **, &) tools.assertions.validate_name(name, as: 'name') if type && !type.is_a?(Module) tools.assertions.validate_name(type, as: 'type') end tools.assertions.validate_name(using, as: 'using') if using validation_rules << build_validation_rule(name:, options:, type:, using:, &) end |
#validate_parameters(command) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/cuprum/parameter_validation.rb', line 127 def validate_parameters(command, ...) parameters = parameters_mapping.call(...) rules = each_validation Validator.new.call(command:, parameters:, rules:) rescue NameError => exception raise unless exception.name == :process error = Cuprum::Errors::CommandNotImplemented.new(command:) Cuprum::Result.new(error:) end |