Sha256: 5ddd74f6328bc6f8feeca5657a998e80ec1ecca241d21a48b4295a9588a88a67

Contents?: true

Size: 1.29 KB

Versions: 14

Compression:

Stored size: 1.29 KB

Contents

module Foobara
  module BuiltinTypes
    module Duck
      module SupportedValidators
        class OneOf < TypeDeclarations::Validator
          class << self
            def requires_parent_declaration_data?
              true
            end
          end

          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 applicable?(value)
            # Might there be some way this validator could be marked not-applicable that doesn't require coupling
            # this processor to allow_nil? (or vice-versa)
            !value.nil? || !parent_declaration_data[:allow_nil]
          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

14 entries across 14 versions & 1 rubygems

Version Path
foobara-0.0.26 projects/builtin_types/src/duck/supported_validators/one_of.rb
foobara-0.0.25 projects/builtin_types/src/duck/supported_validators/one_of.rb
foobara-0.0.24 projects/builtin_types/src/duck/supported_validators/one_of.rb
foobara-0.0.23 projects/builtin_types/src/duck/supported_validators/one_of.rb
foobara-0.0.22 projects/builtin_types/src/duck/supported_validators/one_of.rb
foobara-0.0.21 projects/builtin_types/src/duck/supported_validators/one_of.rb
foobara-0.0.20 projects/builtin_types/src/duck/supported_validators/one_of.rb
foobara-0.0.19 projects/builtin_types/src/duck/supported_validators/one_of.rb
foobara-0.0.18 projects/builtin_types/src/duck/supported_validators/one_of.rb
foobara-0.0.17 projects/builtin_types/src/duck/supported_validators/one_of.rb
foobara-0.0.16 projects/builtin_types/src/duck/supported_validators/one_of.rb
foobara-0.0.15 projects/builtin_types/src/duck/supported_validators/one_of.rb
foobara-0.0.14 projects/builtin_types/src/duck/supported_validators/one_of.rb
foobara-0.0.13 projects/builtin_types/src/duck/supported_validators/one_of.rb