Class: Intrinsic::EventTypeField
- Inherits:
-
Object
- Object
- Intrinsic::EventTypeField
- Defined in:
- lib/intrinsic/types/event_type_field.rb
Instance Attribute Summary collapse
-
#additional_properties ⇒ Object
readonly
Returns the value of attribute additional_properties.
-
#field_name ⇒ Object
readonly
Returns the value of attribute field_name.
-
#optional ⇒ Object
readonly
Returns the value of attribute optional.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
-
.from_json(json_object:) ⇒ EventTypeField
Deserialize a JSON object to an instance of EventTypeField.
-
.validate_raw(obj:) ⇒ Void
Leveraged for Union-type generation, validate_raw attempts to parse the given hash and check each fields type against the current object’s property definitions.
Instance Method Summary collapse
- #initialize(field_name:, type:, optional:, additional_properties: nil) ⇒ EventTypeField constructor
-
#to_json(*_args) ⇒ JSON
Serialize an instance of EventTypeField to a JSON object.
Constructor Details
#initialize(field_name:, type:, optional:, additional_properties: nil) ⇒ EventTypeField
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/intrinsic/types/event_type_field.rb', line 15 def initialize(field_name:, type:, optional:, additional_properties: nil) # @type [String] Name of the field. Must be unique, and can only contain alphanumeric characters and underscores, and be up to 255 characters @field_name = field_name # @type [EVENT_TYPE_FIELD_TYPE] Type of the field. Can be either strings, numbers, links to JPEG images, or links to video files @type = type # @type [Boolean] Whether the field is optional or not @optional = optional # @type [OpenStruct] Additional properties unmapped to the current class definition @additional_properties = additional_properties end |
Instance Attribute Details
#additional_properties ⇒ Object (readonly)
Returns the value of attribute additional_properties.
8 9 10 |
# File 'lib/intrinsic/types/event_type_field.rb', line 8 def additional_properties @additional_properties end |
#field_name ⇒ Object (readonly)
Returns the value of attribute field_name.
8 9 10 |
# File 'lib/intrinsic/types/event_type_field.rb', line 8 def field_name @field_name end |
#optional ⇒ Object (readonly)
Returns the value of attribute optional.
8 9 10 |
# File 'lib/intrinsic/types/event_type_field.rb', line 8 def optional @optional end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
8 9 10 |
# File 'lib/intrinsic/types/event_type_field.rb', line 8 def type @type end |
Class Method Details
.from_json(json_object:) ⇒ EventTypeField
Deserialize a JSON object to an instance of EventTypeField
30 31 32 33 34 35 36 37 |
# File 'lib/intrinsic/types/event_type_field.rb', line 30 def self.from_json(json_object:) struct = JSON.parse(json_object, object_class: OpenStruct) parsed_json = JSON.parse(json_object) field_name = struct.field_name type = EVENT_TYPE_FIELD_TYPE.key(parsed_json["type"]) || parsed_json["type"] optional = struct.optional new(field_name: field_name, type: type, optional: optional, additional_properties: struct) end |
.validate_raw(obj:) ⇒ Void
Leveraged for Union-type generation, validate_raw attempts to parse the given hash and check each fields type against the current object’s property definitions.
50 51 52 53 54 |
# File 'lib/intrinsic/types/event_type_field.rb', line 50 def self.validate_raw(obj:) obj.field_name.is_a?(String) != false || raise("Passed value for field obj.field_name is not the expected type, validation failed.") obj.type.is_a?(EVENT_TYPE_FIELD_TYPE) != false || raise("Passed value for field obj.type is not the expected type, validation failed.") obj.optional.is_a?(Boolean) != false || raise("Passed value for field obj.optional is not the expected type, validation failed.") end |
Instance Method Details
#to_json(*_args) ⇒ JSON
Serialize an instance of EventTypeField to a JSON object
42 43 44 |
# File 'lib/intrinsic/types/event_type_field.rb', line 42 def to_json(*_args) { "field_name": @field_name, "type": EVENT_TYPE_FIELD_TYPE[@type] || @type, "optional": @optional }.to_json end |