Sha256: f12a6af09fb2c2a700c86fac986bed5612d1f9eb81a0919694d1a58ae53e91f6

Contents?: true

Size: 1.82 KB

Versions: 27

Compression:

Stored size: 1.82 KB

Contents

module Foobara
  module BuiltinTypes
    module Tuple
      module SupportedProcessors
        class ElementTypeDeclarations < TypeDeclarations::ElementProcessor
          module TypeDeclarationExtension
            module ExtendTupleTypeDeclaration
              module TypeDeclarationValidators
                class SizeMatches < TypeDeclarations::TypeDeclarationValidator
                  class IncorrectSizeError < Value::DataError
                    class << self
                      def context_type_declaration
                        {
                          expected_size: :integer,
                          actual_size: :integer,
                          value: :array
                        }
                      end
                    end
                  end

                  def applicable?(strict_type_declaration)
                    strict_type_declaration.key?(:size)
                  end

                  def validation_errors(strict_type_declaration)
                    size = strict_type_declaration[:size]
                    element_type_declarations = strict_type_declaration[:element_type_declarations]
                    element_type_declarations_size = element_type_declarations.size

                    if size != element_type_declarations_size
                      build_error(
                        message: "Expected tuple to have #{size} elements but it had #{element_type_declarations_size}",
                        context: {
                          expected_size: size,
                          actual_size: element_type_declarations_size,
                          value: strict_type_declaration
                        }
                      )
                    end
                  end
                end
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
foobara-0.0.7 projects/builtin_types/src/tuple/supported_processors/element_type_declarations/type_declaration_extension/extend_tuple_type_declaration/type_declaration_validators/size_matches.rb
foobara-0.0.6 projects/builtin_types/src/tuple/supported_processors/element_type_declarations/type_declaration_extension/extend_tuple_type_declaration/type_declaration_validators/size_matches.rb
foobara-0.0.5 projects/builtin_types/src/tuple/supported_processors/element_type_declarations/type_declaration_extension/extend_tuple_type_declaration/type_declaration_validators/size_matches.rb
foobara-0.0.4 projects/builtin_types/src/tuple/supported_processors/element_type_declarations/type_declaration_extension/extend_tuple_type_declaration/type_declaration_validators/size_matches.rb
foobara-0.0.3 projects/builtin_types/src/tuple/supported_processors/element_type_declarations/type_declaration_extension/extend_tuple_type_declaration/type_declaration_validators/size_matches.rb
foobara-0.0.2 projects/builtin_types/src/tuple/supported_processors/element_type_declarations/type_declaration_extension/extend_tuple_type_declaration/type_declaration_validators/size_matches.rb
foobara-0.0.1 projects/builtin_types/src/tuple/supported_processors/element_type_declarations/type_declaration_extension/extend_tuple_type_declaration/type_declaration_validators/size_matches.rb