module Surrealist::ExceptionRaiser

A class that raises all Surrealist exceptions

Constants

CLASS_DOESNT_INCLUDE_SURREALIST
CLASS_NAME_NOT_PASSED
MUST_BEHAVE_LIKE_ENUMERABLE

Public Class Methods

raise_invalid_collection!() click to toggle source

Raises Surrealist::InvalidCollectionError

@raise Surrealist::InvalidCollectionError

# File lib/surrealist/exception_raiser.rb, line 66
def raise_invalid_collection!
  raise Surrealist::InvalidCollectionError, MUST_BEHAVE_LIKE_ENUMERABLE
end
raise_invalid_key!(err) click to toggle source

Raises ArgumentError if a key defined in the schema does not have a corresponding method on the object.

@raise Surrealist::UndefinedMethodError

# File lib/surrealist/exception_raiser.rb, line 90
def raise_invalid_key!(err)
  raise Surrealist::UndefinedMethodError,
        "#{err.message}. You have probably defined a key " \
        "in the schema that doesn't have a corresponding method.",
        err.backtrace
end
raise_invalid_nesting!(value) click to toggle source

Raises ArgumentError if namespaces_nesting_level is not an integer.

@raise ArgumentError

# File lib/surrealist/exception_raiser.rb, line 73
def raise_invalid_nesting!(value)
  raise ArgumentError,
        "Expected `namespaces_nesting_level` to be a positive integer, got: #{value}"
end
raise_invalid_root!(value) click to toggle source

Raises ArgumentError if root is not nil, a non-empty string or symbol.

@raise ArgumentError

# File lib/surrealist/exception_raiser.rb, line 81
def raise_invalid_root!(value)
  raise ArgumentError,
        "Expected `root` to be nil, a non-empty string, or symbol, got: #{value}"
end
raise_invalid_schema_delegation!() click to toggle source

Raises Surrealist::InvalidSchemaDelegation if destination of delegation does not include Surrealist.

@raise Surrealist::InvalidSchemaDelegation

# File lib/surrealist/exception_raiser.rb, line 42
def raise_invalid_schema_delegation!
  raise Surrealist::InvalidSchemaDelegation, CLASS_DOESNT_INCLUDE_SURREALIST
end
raise_unknown_root!() click to toggle source

Raises Surrealist::UnknownRootError if class's name is unknown.

@raise Surrealist::UnknownRootError

# File lib/surrealist/exception_raiser.rb, line 59
def raise_unknown_root!
  raise Surrealist::UnknownRootError, CLASS_NAME_NOT_PASSED
end
raise_unknown_schema!(instance) click to toggle source

Raises Surrealist::UnknownSchemaError

@param [Object] instance instance of the class without schema defined.

@raise Surrealist::UnknownSchemaError

# File lib/surrealist/exception_raiser.rb, line 51
def raise_unknown_schema!(instance)
  raise Surrealist::UnknownSchemaError,
        "Can't serialize #{instance.class} - no schema was provided."
end
raise_unknown_tag!(tag) click to toggle source

Raises ArgumentError if a tag has no corresponding serializer

@param [String] tag Wrong tag

@raise Surrealist::UnknownTagError

# File lib/surrealist/exception_raiser.rb, line 102
def raise_unknown_tag!(tag)
  raise Surrealist::UnknownTagError,
        "The tag specified (#{tag}) has no corresponding serializer"
end