Sha256: ee74f06e018f3af1b76522c3f8dd0c75dd8b2376edd000e30e9c21dc1c970d3c

Contents?: true

Size: 1.44 KB

Versions: 26

Compression:

Stored size: 1.44 KB

Contents

module Foobara
  module BuiltinTypes
    module Attributes
      module SupportedValidators
        class Required < TypeDeclarations::Validator
          class MissingRequiredAttributeError < Foobara::Value::DataError
            class << self
              def context_type_declaration
                {
                  attribute_name: :symbol
                }
              end

              def fatal?
                true
              end
            end
          end

          def applicable?(value)
            value.is_a?(::Hash)
          end

          def required_attribute_names
            required
          end

          def validation_errors(attributes_hash)
            required_attribute_names.map do |required_attribute_name|
              unless attributes_hash.key?(required_attribute_name)
                build_error(
                  message: "Missing required attribute #{required_attribute_name}",
                  context: { attribute_name: required_attribute_name },
                  path: [required_attribute_name]
                )
              end
            end.compact
          end

          def possible_errors
            required_attribute_names.map do |required_attribute_name|
              possible_error = PossibleError.new(error_class, processor: self)
              possible_error.prepend_path!(required_attribute_name)
              possible_error
            end
          end
        end
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
foobara-0.0.26 projects/builtin_types/src/attributes/supported_validators/required.rb
foobara-0.0.25 projects/builtin_types/src/attributes/supported_validators/required.rb
foobara-0.0.24 projects/builtin_types/src/attributes/supported_validators/required.rb
foobara-0.0.23 projects/builtin_types/src/attributes/supported_validators/required.rb
foobara-0.0.22 projects/builtin_types/src/attributes/supported_validators/required.rb
foobara-0.0.21 projects/builtin_types/src/attributes/supported_validators/required.rb
foobara-0.0.20 projects/builtin_types/src/attributes/supported_validators/required.rb
foobara-0.0.19 projects/builtin_types/src/attributes/supported_validators/required.rb
foobara-0.0.18 projects/builtin_types/src/attributes/supported_validators/required.rb
foobara-0.0.17 projects/builtin_types/src/attributes/supported_validators/required.rb
foobara-0.0.16 projects/builtin_types/src/attributes/supported_validators/required.rb
foobara-0.0.15 projects/builtin_types/src/attributes/supported_validators/required.rb
foobara-0.0.14 projects/builtin_types/src/attributes/supported_validators/required.rb
foobara-0.0.13 projects/builtin_types/src/attributes/supported_validators/required.rb
foobara-0.0.12 projects/builtin_types/src/attributes/supported_validators/required.rb
foobara-0.0.11 projects/builtin_types/src/attributes/supported_validators/required.rb
foobara-0.0.10 projects/builtin_types/src/attributes/supported_validators/required.rb
foobara-0.0.9 projects/builtin_types/src/attributes/supported_validators/required.rb
foobara-0.0.8 projects/builtin_types/src/attributes/supported_validators/required.rb
foobara-0.0.7 projects/builtin_types/src/attributes/supported_validators/required.rb