Module: FunctionsFramework::CloudEvents::Event
- Included in:
- V1
- Defined in:
- lib/functions_framework/cloud_events/event.rb,
lib/functions_framework/cloud_events/event/v1.rb
Overview
CloudEvent object.
An Event object represents a complete event, including both its data and its context attributes. The following are true of all event objects:
- Event classes are defined within this module. For example, events conforming to the CloudEvents 1.0 specification are of type V1.
- All event classes include this module, so you can use
is_a? FunctionsFramework::CloudEvents::Event
to test whether an object is an event. - All event objects are immutable. Data and atribute values can be retrieved but not modified. To "modify" an event, make a copy with the desired changes. Generally, event classes will provide a helper method for this purpose.
- All event objects have a
spec_version
method that returns the version of the CloudEvents spec implemented by that event. (Other methods may be different, depending on the spec version.)
To create an event, you may either:
- Construct an instance of the event class directly, for example by calling Event.new and passing a set of attributes.
- Call Event.create and pass a spec version and a set of attributes. This will choose the appropriate event class based on the version.
- Decode an event from another representation. For example, use JsonFormat to decode an event from JSON, or use HttpBinding to decode an event from an HTTP request.
See https://github.com/cloudevents/spec/blob/master/spec.md for more information about CloudEvents.
Defined Under Namespace
Classes: V1
Class Method Summary collapse
-
.create(spec_version:, **kwargs) ⇒ Object
(also: new)
Create a new cloud event object with the given version.
Class Method Details
.create(spec_version:, **kwargs) ⇒ Object Also known as: new
Create a new cloud event object with the given version. Generally,
you must also pass additional keyword arguments providing the event's
data and attributes. For example, if you pass 1.0
as the
spec_version
, the remaining keyword arguments will be passed
through to the new constructor.
67 68 69 70 71 72 73 74 |
# File 'lib/functions_framework/cloud_events/event.rb', line 67 def create spec_version:, **kwargs case spec_version when /^1(\.|$)/ V1.new spec_version: spec_version, **kwargs else raise SpecVersionError, "Unrecognized specversion: #{spec_version}" end end |