Module: Surrealist::ExceptionRaiser
- Defined in:
- lib/surrealist/exception_raiser.rb
Overview
A class that raises all Surrealist exceptions
Constant Summary collapse
- CLASS_NAME_NOT_PASSED =
"Can't wrap schema in root key - class name was not passed"
- MUST_BEHAVE_LIKE_ENUMERABLE =
"Can't serialize collection - must behave like enumerable"
- CLASS_DOESNT_INCLUDE_SURREALIST =
'Class does not include Surrealist'
Class Method Summary collapse
-
.raise_invalid_collection! ⇒ Object
Raises Surrealist::InvalidCollectionError.
-
.raise_invalid_key!(err) ⇒ Object
Raises ArgumentError if a key defined in the schema does not have a corresponding method on the object.
-
.raise_invalid_nesting!(value) ⇒ Object
Raises ArgumentError if namespaces_nesting_level is not an integer.
-
.raise_invalid_root!(value) ⇒ Object
Raises ArgumentError if root is not nil, a non-empty string or symbol.
-
.raise_invalid_schema_delegation! ⇒ Object
Raises Surrealist::InvalidSchemaDelegation if destination of delegation does not include Surrealist.
-
.raise_unknown_root! ⇒ Object
Raises Surrealist::UnknownRootError if class’s name is unknown.
-
.raise_unknown_schema!(instance) ⇒ Object
Raises Surrealist::UnknownSchemaError.
-
.raise_unknown_tag!(tag) ⇒ Object
Raises ArgumentError if a tag has no corresponding serializer.
Class Method Details
.raise_invalid_collection! ⇒ Object
Raises Surrealist::InvalidCollectionError
66 67 68 |
# File 'lib/surrealist/exception_raiser.rb', line 66 def raise_invalid_collection! raise Surrealist::InvalidCollectionError, MUST_BEHAVE_LIKE_ENUMERABLE end |
.raise_invalid_key!(err) ⇒ Object
Raises ArgumentError if a key defined in the schema does not have a corresponding method on the object.
90 91 92 93 94 95 |
# File 'lib/surrealist/exception_raiser.rb', line 90 def raise_invalid_key!(err) raise Surrealist::UndefinedMethodError, "#{err.}. You have probably defined a key " \ "in the schema that doesn't have a corresponding method.", err.backtrace end |
.raise_invalid_nesting!(value) ⇒ Object
Raises ArgumentError if namespaces_nesting_level is not an integer.
73 74 75 76 |
# 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) ⇒ Object
Raises ArgumentError if root is not nil, a non-empty string or symbol.
81 82 83 84 |
# 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! ⇒ Object
Raises Surrealist::InvalidSchemaDelegation if destination of delegation does not include Surrealist.
42 43 44 |
# File 'lib/surrealist/exception_raiser.rb', line 42 def raise_invalid_schema_delegation! raise Surrealist::InvalidSchemaDelegation, CLASS_DOESNT_INCLUDE_SURREALIST end |
.raise_unknown_root! ⇒ Object
Raises Surrealist::UnknownRootError if class’s name is unknown.
59 60 61 |
# File 'lib/surrealist/exception_raiser.rb', line 59 def raise_unknown_root! raise Surrealist::UnknownRootError, CLASS_NAME_NOT_PASSED end |
.raise_unknown_schema!(instance) ⇒ Object
Raises Surrealist::UnknownSchemaError
51 52 53 54 |
# 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) ⇒ Object
Raises ArgumentError if a tag has no corresponding serializer
102 103 104 105 |
# 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 |