Sha256: 900305cd54c04b86d2ee7a65fa223fca0ff503bbeba10683beef97ee7c417395

Contents?: true

Size: 1.03 KB

Versions: 26

Compression:

Stored size: 1.03 KB

Contents

module Foobara
  module BuiltinTypes
    module Array
      module SupportedValidators
        class Size < TypeDeclarations::Validator
          class IncorrectTupleSizeError < Value::DataError
            class << self
              def context_type_declaration
                {
                  expected_size: :integer,
                  actual_size: :integer,
                  value: :array
                }
              end
            end
          end

          def expected_size
            size
          end

          def validation_errors(array)
            if array.size != expected_size
              build_error(array)
            end
          end

          def error_message(array)
            "Invalid tuple size. #{array.inspect} should have had #{expected_size} elements but had #{array.size}."
          end

          def error_context(array)
            {
              expected_size:,
              actual_size: array.size,
              value: array
            }
          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/array/supported_validators/size.rb
foobara-0.0.25 projects/builtin_types/src/array/supported_validators/size.rb
foobara-0.0.24 projects/builtin_types/src/array/supported_validators/size.rb
foobara-0.0.23 projects/builtin_types/src/array/supported_validators/size.rb
foobara-0.0.22 projects/builtin_types/src/array/supported_validators/size.rb
foobara-0.0.21 projects/builtin_types/src/array/supported_validators/size.rb
foobara-0.0.20 projects/builtin_types/src/array/supported_validators/size.rb
foobara-0.0.19 projects/builtin_types/src/array/supported_validators/size.rb
foobara-0.0.18 projects/builtin_types/src/array/supported_validators/size.rb
foobara-0.0.17 projects/builtin_types/src/array/supported_validators/size.rb
foobara-0.0.16 projects/builtin_types/src/array/supported_validators/size.rb
foobara-0.0.15 projects/builtin_types/src/array/supported_validators/size.rb
foobara-0.0.14 projects/builtin_types/src/array/supported_validators/size.rb
foobara-0.0.13 projects/builtin_types/src/array/supported_validators/size.rb
foobara-0.0.12 projects/builtin_types/src/array/supported_validators/size.rb
foobara-0.0.11 projects/builtin_types/src/array/supported_validators/size.rb
foobara-0.0.10 projects/builtin_types/src/array/supported_validators/size.rb
foobara-0.0.9 projects/builtin_types/src/array/supported_validators/size.rb
foobara-0.0.8 projects/builtin_types/src/array/supported_validators/size.rb
foobara-0.0.7 projects/builtin_types/src/array/supported_validators/size.rb