Class: CloudEvents::Event::Opaque

Inherits:
Object
  • Object
show all
Defined in:
lib/cloud_events/event/opaque.rb

Overview

This object represents opaque event data that arrived in structured content mode but was not in a recognized format. It may represent a single event or a batch of events.

The event data is retained in a form that can be reserialized (in a structured cotent mode in the same format) but cannot otherwise be inspected.

This object is immutable, and Ractor-shareable on Ruby 3.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content, content_type, batch: nil) ⇒ Opaque

Create an opaque object wrapping the given content and a content type.

Parameters:

  • content (String)

    The opaque serialized event data.

  • content_type (CloudEvents::ContentType, nil)

    The content type, or nil if there is no content type.

  • batch (boolean) (defaults to: nil)

    Whether this represents a batch. If set to nil or not provided, the value will be inferred from the content type if possible, or otherwise set to nil indicating not known.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/cloud_events/event/opaque.rb', line 27

def initialize content, content_type, batch: nil
  @content = content.freeze
  @content_type = content_type
  if batch.nil? && content_type&.media_type == "application"
    case content_type.subtype_base
    when "cloudevents"
      batch = false
    when "cloudevents-batch"
      batch = true
    end
  end
  @batch = batch
  freeze
end

Instance Attribute Details

#contentString (readonly)

The opaque serialized event data

Returns:

  • (String)


47
48
49
# File 'lib/cloud_events/event/opaque.rb', line 47

def content
  @content
end

#content_typeCloudEvents::ContentType? (readonly)

The content type, or nil if there is no content type.

Returns:



54
55
56
# File 'lib/cloud_events/event/opaque.rb', line 54

def content_type
  @content_type
end

Instance Method Details

#batch?boolean?

Whether this represents a batch, or nil if not known.

Returns:

  • (boolean, nil)


61
62
63
# File 'lib/cloud_events/event/opaque.rb', line 61

def batch?
  @batch
end