Sha256: 90d919b129b0b028ab87df76b4039fa4f95d2ce88af63ba7363a46632873822d

Contents?: true

Size: 1.96 KB

Versions: 26

Compression:

Stored size: 1.96 KB

Contents

module Foobara
  module BuiltinTypes
    module Attributes
      module SupportedValidators
        class Required < TypeDeclarations::Validator
          module TypeDeclarationExtension
            module ExtendAttributesTypeDeclaration
              module TypeDeclarationValidators
                class ArrayWithValidAttributeNames < TypeDeclarations::TypeDeclarationValidator
                  class InvalidRequiredAttributeNameGivenError < Value::DataError
                    class << self
                      def context_type_declaration
                        {
                          invalid_required_attribute_name: :symbol,
                          valid_attribute_names: [:symbol],
                          required: [:symbol]
                        }
                      end
                    end
                  end

                  def applicable?(strict_type_declaration)
                    required = strict_type_declaration[:required]

                    required.is_a?(::Array) && Util.all_symbolic_elements?(required)
                  end

                  def validation_errors(strict_type_declaration)
                    required = strict_type_declaration[:required]

                    valid_attribute_names = strict_type_declaration[:element_type_declarations].keys

                    required.map do |key|
                      unless valid_attribute_names.include?(key)
                        build_error(
                          message: "#{key} is not a valid default key, expected one of #{valid_attribute_names}",
                          context: {
                            invalid_required_attribute_name: key,
                            valid_attribute_names:,
                            required:
                          }
                        )
                      end
                    end.compact
                  end
                end
              end
            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/type_declaration_extension/extend_attributes_type_declaration/type_declaration_validators/array_with_valid_attribute_names.rb
foobara-0.0.25 projects/builtin_types/src/attributes/supported_validators/required/type_declaration_extension/extend_attributes_type_declaration/type_declaration_validators/array_with_valid_attribute_names.rb
foobara-0.0.24 projects/builtin_types/src/attributes/supported_validators/required/type_declaration_extension/extend_attributes_type_declaration/type_declaration_validators/array_with_valid_attribute_names.rb
foobara-0.0.23 projects/builtin_types/src/attributes/supported_validators/required/type_declaration_extension/extend_attributes_type_declaration/type_declaration_validators/array_with_valid_attribute_names.rb
foobara-0.0.22 projects/builtin_types/src/attributes/supported_validators/required/type_declaration_extension/extend_attributes_type_declaration/type_declaration_validators/array_with_valid_attribute_names.rb
foobara-0.0.21 projects/builtin_types/src/attributes/supported_validators/required/type_declaration_extension/extend_attributes_type_declaration/type_declaration_validators/array_with_valid_attribute_names.rb
foobara-0.0.20 projects/builtin_types/src/attributes/supported_validators/required/type_declaration_extension/extend_attributes_type_declaration/type_declaration_validators/array_with_valid_attribute_names.rb
foobara-0.0.19 projects/builtin_types/src/attributes/supported_validators/required/type_declaration_extension/extend_attributes_type_declaration/type_declaration_validators/array_with_valid_attribute_names.rb
foobara-0.0.18 projects/builtin_types/src/attributes/supported_validators/required/type_declaration_extension/extend_attributes_type_declaration/type_declaration_validators/array_with_valid_attribute_names.rb
foobara-0.0.17 projects/builtin_types/src/attributes/supported_validators/required/type_declaration_extension/extend_attributes_type_declaration/type_declaration_validators/array_with_valid_attribute_names.rb
foobara-0.0.16 projects/builtin_types/src/attributes/supported_validators/required/type_declaration_extension/extend_attributes_type_declaration/type_declaration_validators/array_with_valid_attribute_names.rb
foobara-0.0.15 projects/builtin_types/src/attributes/supported_validators/required/type_declaration_extension/extend_attributes_type_declaration/type_declaration_validators/array_with_valid_attribute_names.rb
foobara-0.0.14 projects/builtin_types/src/attributes/supported_validators/required/type_declaration_extension/extend_attributes_type_declaration/type_declaration_validators/array_with_valid_attribute_names.rb
foobara-0.0.13 projects/builtin_types/src/attributes/supported_validators/required/type_declaration_extension/extend_attributes_type_declaration/type_declaration_validators/array_with_valid_attribute_names.rb
foobara-0.0.12 projects/builtin_types/src/attributes/supported_validators/required/type_declaration_extension/extend_attributes_type_declaration/type_declaration_validators/array_with_valid_attribute_names.rb
foobara-0.0.11 projects/builtin_types/src/attributes/supported_validators/required/type_declaration_extension/extend_attributes_type_declaration/type_declaration_validators/array_with_valid_attribute_names.rb
foobara-0.0.10 projects/builtin_types/src/attributes/supported_validators/required/type_declaration_extension/extend_attributes_type_declaration/type_declaration_validators/array_with_valid_attribute_names.rb
foobara-0.0.9 projects/builtin_types/src/attributes/supported_validators/required/type_declaration_extension/extend_attributes_type_declaration/type_declaration_validators/array_with_valid_attribute_names.rb
foobara-0.0.8 projects/builtin_types/src/attributes/supported_validators/required/type_declaration_extension/extend_attributes_type_declaration/type_declaration_validators/array_with_valid_attribute_names.rb
foobara-0.0.7 projects/builtin_types/src/attributes/supported_validators/required/type_declaration_extension/extend_attributes_type_declaration/type_declaration_validators/array_with_valid_attribute_names.rb