Sha256: 5a6f00354cb47f5d55316420ac43c4686038d870232cc36b4c946fc025195f4e

Contents?: true

Size: 1.56 KB

Versions: 26

Compression:

Stored size: 1.56 KB

Contents

module Foobara
  module BuiltinTypes
    module Duck
      module SupportedValidators
        class InstanceOf < TypeDeclarations::Validator
          module TypeDeclarationExtension
            module ExtendRegisteredTypeDeclaration
              module TypeDeclarationValidators
                class IsValidClass < TypeDeclarations::TypeDeclarationValidator
                  class InvalidInstanceOfValueGivenError < Value::DataError
                    class << self
                      def message
                        "instance_of: should be a class or the name of an existing class"
                      end
                    end
                  end

                  def applicable?(strict_type_declaration)
                    strict_type_declaration.is_a?(Hash) && strict_type_declaration.key?(:instance_of)
                  end

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

                    return if instance_of.is_a?(::Class)

                    if instance_of.is_a?(::String) || instance_of.is_a?(::Symbol)
                      unless Object.const_defined?(instance_of)
                        build_error(context: { attribute_name: :instance_of, value: instance_of })
                      end
                    else
                      build_error(context: { attribute_name: :instance_of, value: instance_of })
                    end
                  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/duck/supported_validators/instance_of/type_declaration_extension/extend_registered_type_declaration/type_declaration_validators/is_valid_class.rb
foobara-0.0.25 projects/builtin_types/src/duck/supported_validators/instance_of/type_declaration_extension/extend_registered_type_declaration/type_declaration_validators/is_valid_class.rb
foobara-0.0.24 projects/builtin_types/src/duck/supported_validators/instance_of/type_declaration_extension/extend_registered_type_declaration/type_declaration_validators/is_valid_class.rb
foobara-0.0.23 projects/builtin_types/src/duck/supported_validators/instance_of/type_declaration_extension/extend_registered_type_declaration/type_declaration_validators/is_valid_class.rb
foobara-0.0.22 projects/builtin_types/src/duck/supported_validators/instance_of/type_declaration_extension/extend_registered_type_declaration/type_declaration_validators/is_valid_class.rb
foobara-0.0.21 projects/builtin_types/src/duck/supported_validators/instance_of/type_declaration_extension/extend_registered_type_declaration/type_declaration_validators/is_valid_class.rb
foobara-0.0.20 projects/builtin_types/src/duck/supported_validators/instance_of/type_declaration_extension/extend_registered_type_declaration/type_declaration_validators/is_valid_class.rb
foobara-0.0.19 projects/builtin_types/src/duck/supported_validators/instance_of/type_declaration_extension/extend_registered_type_declaration/type_declaration_validators/is_valid_class.rb
foobara-0.0.18 projects/builtin_types/src/duck/supported_validators/instance_of/type_declaration_extension/extend_registered_type_declaration/type_declaration_validators/is_valid_class.rb
foobara-0.0.17 projects/builtin_types/src/duck/supported_validators/instance_of/type_declaration_extension/extend_registered_type_declaration/type_declaration_validators/is_valid_class.rb
foobara-0.0.16 projects/builtin_types/src/duck/supported_validators/instance_of/type_declaration_extension/extend_registered_type_declaration/type_declaration_validators/is_valid_class.rb
foobara-0.0.15 projects/builtin_types/src/duck/supported_validators/instance_of/type_declaration_extension/extend_registered_type_declaration/type_declaration_validators/is_valid_class.rb
foobara-0.0.14 projects/builtin_types/src/duck/supported_validators/instance_of/type_declaration_extension/extend_registered_type_declaration/type_declaration_validators/is_valid_class.rb
foobara-0.0.13 projects/builtin_types/src/duck/supported_validators/instance_of/type_declaration_extension/extend_registered_type_declaration/type_declaration_validators/is_valid_class.rb
foobara-0.0.12 projects/builtin_types/src/duck/supported_validators/instance_of/type_declaration_extension/extend_registered_type_declaration/type_declaration_validators/is_valid_class.rb
foobara-0.0.11 projects/builtin_types/src/duck/supported_validators/instance_of/type_declaration_extension/extend_registered_type_declaration/type_declaration_validators/is_valid_class.rb
foobara-0.0.10 projects/builtin_types/src/duck/supported_validators/instance_of/type_declaration_extension/extend_registered_type_declaration/type_declaration_validators/is_valid_class.rb
foobara-0.0.9 projects/builtin_types/src/duck/supported_validators/instance_of/type_declaration_extension/extend_registered_type_declaration/type_declaration_validators/is_valid_class.rb
foobara-0.0.8 projects/builtin_types/src/duck/supported_validators/instance_of/type_declaration_extension/extend_registered_type_declaration/type_declaration_validators/is_valid_class.rb
foobara-0.0.7 projects/builtin_types/src/duck/supported_validators/instance_of/type_declaration_extension/extend_registered_type_declaration/type_declaration_validators/is_valid_class.rb