Sha256: 2f0eea9c17c8b1a067ea1923a0e7c7b8c3b03e9fd063e1ccbc4606cb2a7e33e0

Contents?: true

Size: 1.28 KB

Versions: 8

Compression:

Stored size: 1.28 KB

Contents

module Foobara
  module TypeDeclarations
    module Handlers
      class ExtendDetachedEntityTypeDeclaration < ExtendModelTypeDeclaration
        class ValidatePrimaryKeyReferencesAttribute < TypeDeclarations::TypeDeclarationValidator
          class InvalidPrimaryKeyError < TypeDeclarationError
            class << self
              def context_type_declaration
                {
                  allowed_primary_keys: [:symbol],
                  primary_key: :symbol
                }
              end
            end
          end

          def applicable?(strict_type_declaration)
            strict_type_declaration.key?(:primary_key) && strict_type_declaration[:primary_key].is_a?(::Symbol)
          end

          def validation_errors(strict_type_declaration)
            allowed_primary_keys = strict_type_declaration[:attributes_declaration][:element_type_declarations].keys

            primary_key = strict_type_declaration[:primary_key]
            unless allowed_primary_keys.include?(primary_key)
              build_error(
                message: "Invalid primary key. Expected #{primary_key} to be one of #{allowed_primary_keys}",
                context: { allowed_primary_keys:, primary_key: }
              )
            end
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
foobara-0.0.38 projects/detached_entity/src/extensions/type_declarations/handlers/extend_detached_entity_type_declaration/validate_primary_key_references_attribute.rb
foobara-0.0.37 projects/detached_entity/src/extensions/type_declarations/handlers/extend_detached_entity_type_declaration/validate_primary_key_references_attribute.rb
foobara-0.0.36 projects/detached_entity/src/extensions/type_declarations/handlers/extend_detached_entity_type_declaration/validate_primary_key_references_attribute.rb
foobara-0.0.35 projects/detached_entity/src/extensions/type_declarations/handlers/extend_detached_entity_type_declaration/validate_primary_key_references_attribute.rb
foobara-0.0.34 projects/detached_entity/src/extensions/type_declarations/handlers/extend_detached_entity_type_declaration/validate_primary_key_references_attribute.rb
foobara-0.0.33 projects/detached_entity/src/extensions/type_declarations/handlers/extend_detached_entity_type_declaration/validate_primary_key_references_attribute.rb
foobara-0.0.32 projects/detached_entity/src/extensions/type_declarations/handlers/extend_detached_entity_type_declaration/validate_primary_key_references_attribute.rb
foobara-0.0.31 projects/detached_entity/src/extensions/type_declarations/handlers/extend_detached_entity_type_declaration/validate_primary_key_references_attribute.rb