Sha256: 6baca8f20be9243c990283ddc0dda1e1de15dc970e837599e2cc0bb8b67fa8ac

Contents?: true

Size: 1.44 KB

Versions: 26

Compression:

Stored size: 1.44 KB

Contents

module Foobara
  module TypeDeclarations
    module Handlers
      class ExtendRegisteredModelTypeDeclaration < ExtendRegisteredTypeDeclaration
        class MutableValidator < TypeDeclarations::TypeDeclarationValidator
          class InvalidMutableValueGivenError < Value::DataError
            class << self
              def context_type_declaration
                {
                  invalid_key: :symbol,
                  valid_attribute_names: [:symbol],
                  mutable: [:symbol]
                }
              end
            end
          end

          def applicable?(value)
            value.key?(:mutable)
          end

          def validation_errors(strict_type_declaration)
            mutable = strict_type_declaration[:mutable]
            return if [true, false].include?(mutable)

            model_type = type_for_declaration(strict_type_declaration[:type])
            valid_attribute_names = model_type.element_types.element_types.keys

            mutable.map do |key|
              unless valid_attribute_names.include?(key)
                build_error(
                  message: "#{key} is not a valid attribute, expected one of #{valid_attribute_names}",
                  context: {
                    invalid_key: key,
                    valid_attribute_names:,
                    mutable:
                  }
                )
              end
            end.compact
          end
        end
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
foobara-0.0.26 projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/mutable_validator.rb
foobara-0.0.25 projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/mutable_validator.rb
foobara-0.0.24 projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/mutable_validator.rb
foobara-0.0.23 projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/mutable_validator.rb
foobara-0.0.22 projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/mutable_validator.rb
foobara-0.0.21 projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/mutable_validator.rb
foobara-0.0.20 projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/mutable_validator.rb
foobara-0.0.19 projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/mutable_validator.rb
foobara-0.0.18 projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/mutable_validator.rb
foobara-0.0.17 projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/mutable_validator.rb
foobara-0.0.16 projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/mutable_validator.rb
foobara-0.0.15 projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/mutable_validator.rb
foobara-0.0.14 projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/mutable_validator.rb
foobara-0.0.13 projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/mutable_validator.rb
foobara-0.0.12 projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/mutable_validator.rb
foobara-0.0.11 projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/mutable_validator.rb
foobara-0.0.10 projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/mutable_validator.rb
foobara-0.0.9 projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/mutable_validator.rb
foobara-0.0.8 projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/mutable_validator.rb
foobara-0.0.7 projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/mutable_validator.rb