Class: CoreLibrary::UnionType
- Inherits:
-
Object
- Object
- CoreLibrary::UnionType
- Defined in:
- lib/apimatic-core-interfaces/types/union_type.rb
Overview
Represents a union type that can validate, serialize and deserialize values based on a set of allowed types.
Constant Summary collapse
- NATIVE_TYPES =
NATIVE_TYPES represents the list of native types in Ruby. These types are commonly used and built-in to the Ruby language. The constant contains the following types:
-
Integer: Represents whole numbers without a decimal point.
-
String: Represents a sequence of characters.
-
Float: Represents floating-point numbers with a decimal point.
-
TrueClass: Represents the boolean value ‘true`.
-
FalseClass: Represents the boolean value ‘false`.
This constant is used within the UnionType class to define the allowed native types.
-
[Integer, String, Float, TrueClass, FalseClass].freeze
Instance Attribute Summary collapse
-
#error_messages ⇒ Object
Returns the value of attribute error_messages.
-
#is_valid ⇒ Object
Returns the value of attribute is_valid.
-
#union_type_context ⇒ Object
Returns the value of attribute union_type_context.
-
#union_types ⇒ Object
Returns the value of attribute union_types.
Instance Method Summary collapse
-
#deserialize(value, should_symbolize: false) ⇒ Object
Deserializes a value based on the union type.
-
#initialize(union_types, union_type_context) ⇒ UnionType
constructor
Initializes a new instance of UnionType.
-
#serialize(value) ⇒ String
Serializes a given value.
-
#validate(value) ⇒ Object
Validates a value against the union type.
Constructor Details
#initialize(union_types, union_type_context) ⇒ UnionType
Initializes a new instance of UnionType.
20 21 22 23 24 25 |
# File 'lib/apimatic-core-interfaces/types/union_type.rb', line 20 def initialize(union_types, union_type_context) @union_types = union_types @union_type_context = union_type_context @is_valid = false @error_messages = Set.new end |
Instance Attribute Details
#error_messages ⇒ Object
Returns the value of attribute error_messages.
15 16 17 |
# File 'lib/apimatic-core-interfaces/types/union_type.rb', line 15 def @error_messages end |
#is_valid ⇒ Object
Returns the value of attribute is_valid.
15 16 17 |
# File 'lib/apimatic-core-interfaces/types/union_type.rb', line 15 def is_valid @is_valid end |
#union_type_context ⇒ Object
Returns the value of attribute union_type_context.
15 16 17 |
# File 'lib/apimatic-core-interfaces/types/union_type.rb', line 15 def union_type_context @union_type_context end |
#union_types ⇒ Object
Returns the value of attribute union_types.
15 16 17 |
# File 'lib/apimatic-core-interfaces/types/union_type.rb', line 15 def union_types @union_types end |
Instance Method Details
#deserialize(value, should_symbolize: false) ⇒ Object
Deserializes a value based on the union type. This method should be implemented by subclasses.
50 51 52 53 |
# File 'lib/apimatic-core-interfaces/types/union_type.rb', line 50 def deserialize(value, should_symbolize: false) raise NotImplementedError, 'This method needs to be implemented in a child class.' end |
#serialize(value) ⇒ String
Serializes a given value.
40 41 42 43 |
# File 'lib/apimatic-core-interfaces/types/union_type.rb', line 40 def serialize(value) raise NotImplementedError, 'This method needs to be implemented in a child class.' end |
#validate(value) ⇒ Object
Validates a value against the union type. This method should be implemented by subclasses.
31 32 33 34 |
# File 'lib/apimatic-core-interfaces/types/union_type.rb', line 31 def validate(value) raise NotImplementedError, 'This method needs to be implemented in a child class.' end |