Class: CoreLibrary::LeafType
- Inherits:
-
UnionType
- Object
- UnionType
- CoreLibrary::LeafType
- Defined in:
- lib/apimatic-core/types/union_types/leaf_type.rb
Overview
Represents a leaf type in a UnionType
Instance Attribute Summary collapse
-
#type_to_match ⇒ Object
readonly
Returns the value of attribute type_to_match.
Instance Method Summary collapse
-
#deserialize(value, should_symbolize: false) ⇒ Object?
Deserializes a value based on the leaf type.
-
#initialize(type_to_match, union_type_context = UnionTypeContext.new) ⇒ LeafType
constructor
Initializes a new instance of LeafType.
- #serialize(value) ⇒ Object
-
#validate(value) ⇒ LeafType
Validates a value against the leaf type.
Constructor Details
#initialize(type_to_match, union_type_context = UnionTypeContext.new) ⇒ LeafType
Initializes a new instance of LeafType
9 10 11 12 |
# File 'lib/apimatic-core/types/union_types/leaf_type.rb', line 9 def initialize(type_to_match, union_type_context = UnionTypeContext.new) super(nil, union_type_context) @type_to_match = type_to_match end |
Instance Attribute Details
#type_to_match ⇒ Object (readonly)
Returns the value of attribute type_to_match.
4 5 6 |
# File 'lib/apimatic-core/types/union_types/leaf_type.rb', line 4 def type_to_match @type_to_match end |
Instance Method Details
#deserialize(value, should_symbolize: false) ⇒ Object?
Deserializes a value based on the leaf type
39 40 41 42 43 |
# File 'lib/apimatic-core/types/union_types/leaf_type.rb', line 39 def deserialize(value, should_symbolize: false) return nil if value.nil? deserialize_value_against_case(value, @union_type_context, should_symbolize: should_symbolize) end |
#serialize(value) ⇒ Object
29 30 31 32 33 |
# File 'lib/apimatic-core/types/union_types/leaf_type.rb', line 29 def serialize(value) return nil if value.nil? serialize_value_against_case(value, @union_type_context) end |
#validate(value) ⇒ LeafType
Validates a value against the leaf type
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/apimatic-core/types/union_types/leaf_type.rb', line 17 def validate(value) context = @union_type_context @is_valid = if value.nil? context.nullable_or_optional? else validate_value_against_case(value, context) end self end |