Sha256: af03b6b891de37fc2e9e05e836c593d89f283c785a31984e3222896c06da53cd

Contents?: true

Size: 917 Bytes

Versions: 12

Compression:

Stored size: 917 Bytes

Contents

module Foobara
  module BuiltinTypes
    module Duck
      module SupportedValidators
        class OneOf < TypeDeclarations::Validator
          class ValueNotValidError < Foobara::Value::DataError
            class << self
              def context_type_declaration
                {
                  value: :duck,
                  valid_values: [:duck]
                }
              end
            end
          end

          def valid_values
            declaration_data
          end

          def validation_errors(value)
            unless valid_values.include?(value)
              build_error(value)
            end
          end

          def error_message(value)
            "#{value} is not one of #{valid_values}"
          end

          def error_context(value)
            {
              value:,
              valid_values:
            }
          end
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
foobara-0.0.12 projects/builtin_types/src/duck/supported_validators/one_of.rb
foobara-0.0.11 projects/builtin_types/src/duck/supported_validators/one_of.rb
foobara-0.0.10 projects/builtin_types/src/duck/supported_validators/one_of.rb
foobara-0.0.9 projects/builtin_types/src/duck/supported_validators/one_of.rb
foobara-0.0.8 projects/builtin_types/src/duck/supported_validators/one_of.rb
foobara-0.0.7 projects/builtin_types/src/duck/supported_validators/one_of.rb
foobara-0.0.6 projects/builtin_types/src/duck/supported_validators/one_of.rb
foobara-0.0.5 projects/builtin_types/src/duck/supported_validators/one_of.rb
foobara-0.0.4 projects/builtin_types/src/duck/supported_validators/one_of.rb
foobara-0.0.3 projects/builtin_types/src/duck/supported_validators/one_of.rb
foobara-0.0.2 projects/builtin_types/src/duck/supported_validators/one_of.rb
foobara-0.0.1 projects/builtin_types/src/duck/supported_validators/one_of.rb