Sha256: 9f13b4737ec577d72697480d7e84817721312696633e8473113e6be49a567d81

Contents?: true

Size: 1006 Bytes

Versions: 26

Compression:

Stored size: 1006 Bytes

Contents

module Foobara
  module BuiltinTypes
    module Duck
      module SupportedValidators
        class InstanceOf < TypeDeclarations::Validator
          class NotInstanceOfError < Foobara::Value::DataError
            class << self
              def context_type_declaration
                {
                  value: :duck,
                  expected_class_name: :string
                }
              end
            end
          end

          def expected_class_name
            declaration_data
          end

          def validation_errors(value)
            klass = Object.const_get(expected_class_name)
            unless value.is_a?(klass)
              build_error(value)
            end
          end

          def error_message(value)
            "#{value} is not an instance of #{expected_class_name}"
          end

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