Class: FunctionsFramework::CloudEvents::Event
- Inherits:
-
Object
- Object
- FunctionsFramework::CloudEvents::Event
- Defined in:
- lib/functions_framework/cloud_events/event.rb
Overview
A cloud event data type.
This object represents both the event data and the context attributes. It is immutable. The data and attribute values can be retrieved but not modified. To obtain an event with modifications, use the #with method to create a copy with the desired changes.
See https://github.com/cloudevents/spec/blob/master/spec.md for descriptions of the various attributes.
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
The event-specific data, or
nilif there is no data. -
#data_content_type ⇒ FunctionsFramework::CloudEvents::ContentType?
(also: #datacontenttype)
readonly
The optional
datacontenttypefield as a ContentType object, ornilif the field is absent. -
#data_content_type_string ⇒ String?
(also: #datacontenttype_string)
readonly
The string representation of the optional
datacontenttypefield, ornilif the field is absent. -
#data_schema ⇒ URI?
(also: #dataschema)
readonly
The optional
dataschemafield as aURIobject, ornilif the field is absent. -
#data_schema_string ⇒ String?
(also: #dataschema_string)
readonly
The string representation of the optional
dataschemafield, ornilif the field is absent. -
#id ⇒ String
readonly
The
idfield. -
#source ⇒ URI
readonly
The
sourcefield as aURIobject. -
#source_string ⇒ String
readonly
The string representation of the
sourcefield. -
#spec_version ⇒ String
(also: #specversion)
readonly
The
specversionfield. -
#subject ⇒ String?
readonly
The optional
subjectfield, ornilif the field is absent. -
#time ⇒ DateTime?
readonly
The optional
timefield as aDateTimeobject, ornilif the field is absent. -
#time_string ⇒ String?
readonly
The string representation of the optional
timefield, ornilif the field is absent. -
#type ⇒ String
readonly
The
typefield.
Instance Method Summary collapse
-
#initialize(id:, source:, type:, spec_version:, data: nil, data_content_type: nil, data_schema: nil, subject: nil, time: nil) ⇒ Event
constructor
Create a new cloud event object with the given data and attributes.
-
#with(**changes) ⇒ FunctionFramework::CloudEvents::Event
Create and return a copy of this event with the given changes.
Constructor Details
#initialize(id:, source:, type:, spec_version:, data: nil, data_content_type: nil, data_schema: nil, subject: nil, time: nil) ⇒ Event
Create a new cloud event object with the given data and attributes.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/functions_framework/cloud_events/event.rb', line 47 def initialize \ id:, source:, type:, spec_version:, data: nil, data_content_type: nil, data_schema: nil, subject: nil, time: nil @id = interpret_string "id", id, true @source, @source_string = interpret_uri "source", source, true @type = interpret_string "type", type, true @spec_version = interpret_string "spec_version", spec_version, true @data = data @data_content_type, @data_content_type_string = interpret_content_type "data_content_type", data_content_type @data_schema, @data_schema_string = interpret_uri "data_schema", data_schema @subject = interpret_string "subject", subject @time, @time_string = interpret_date_time "time", time end |
Instance Attribute Details
#data ⇒ Object (readonly)
The event-specific data, or nil if there is no data.
Data may be one of the following types:
- Binary data, represented by a
StringusingASCII-8BITencoding - A string in some other encoding such as
UTF-8orUS-ASCII - Any JSON data type, such as String, boolean, Integer, Array, or Hash
133 134 135 |
# File 'lib/functions_framework/cloud_events/event.rb', line 133 def data @data end |
#data_content_type ⇒ FunctionsFramework::CloudEvents::ContentType? (readonly) Also known as: datacontenttype
The optional datacontenttype field as a
ContentType object, or nil if the
field is absent
142 143 144 |
# File 'lib/functions_framework/cloud_events/event.rb', line 142 def data_content_type @data_content_type end |
#data_content_type_string ⇒ String? (readonly) Also known as: datacontenttype_string
The string representation of the optional datacontenttype field, or
nil if the field is absent
151 152 153 |
# File 'lib/functions_framework/cloud_events/event.rb', line 151 def data_content_type_string @data_content_type_string end |
#data_schema ⇒ URI? (readonly) Also known as: dataschema
The optional dataschema field as a URI object, or nil if the
field is absent
160 161 162 |
# File 'lib/functions_framework/cloud_events/event.rb', line 160 def data_schema @data_schema end |
#data_schema_string ⇒ String? (readonly) Also known as: dataschema_string
The string representation of the optional dataschema field, or nil
if the field is absent
169 170 171 |
# File 'lib/functions_framework/cloud_events/event.rb', line 169 def data_schema_string @data_schema_string end |
#id ⇒ String (readonly)
The id field
96 97 98 |
# File 'lib/functions_framework/cloud_events/event.rb', line 96 def id @id end |
#source ⇒ URI (readonly)
The source field as a URI object
102 103 104 |
# File 'lib/functions_framework/cloud_events/event.rb', line 102 def source @source end |
#source_string ⇒ String (readonly)
The string representation of the source field
108 109 110 |
# File 'lib/functions_framework/cloud_events/event.rb', line 108 def source_string @source_string end |
#spec_version ⇒ String (readonly) Also known as: specversion
The specversion field
120 121 122 |
# File 'lib/functions_framework/cloud_events/event.rb', line 120 def spec_version @spec_version end |
#subject ⇒ String? (readonly)
The optional subject field, or nil if the field is absent
177 178 179 |
# File 'lib/functions_framework/cloud_events/event.rb', line 177 def subject @subject end |
#time ⇒ DateTime? (readonly)
The optional time field as a DateTime object, or nil if the field
is absent
185 186 187 |
# File 'lib/functions_framework/cloud_events/event.rb', line 185 def time @time end |
#time_string ⇒ String? (readonly)
The string representation of the optional time field, or nil if the
field is absent
193 194 195 |
# File 'lib/functions_framework/cloud_events/event.rb', line 193 def time_string @time_string end |
#type ⇒ String (readonly)
The type field
114 115 116 |
# File 'lib/functions_framework/cloud_events/event.rb', line 114 def type @type end |
Instance Method Details
#with(**changes) ⇒ FunctionFramework::CloudEvents::Event
Create and return a copy of this event with the given changes. See the constructor for the parameters that can be passed.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/functions_framework/cloud_events/event.rb', line 76 def with **changes params = { id: id, source: source, type: type, spec_version: spec_version, data: data, data_content_type: data_content_type, data_schema: data_schema, subject: subject, time: time } params.merge! changes Event.new(**params) end |