Class: Hatchet::DefaultFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/hatchet/default_filter.rb

Overview

Defines a default filter for event-triggered workflows

Examples:

Filter with scope and payload

Hatchet::DefaultFilter.new(
  expression: "true",
  scope: "example-scope",
  payload: { "main_character" => "Anna" }
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expression:, scope: nil, payload: {}) ⇒ DefaultFilter

Returns a new instance of DefaultFilter.

Parameters:

  • expression (String)

    CEL expression

  • scope (String, nil) (defaults to: nil)

    Filter scope

  • payload (Hash) (defaults to: {})

    Static payload (default: {})



25
26
27
28
29
# File 'lib/hatchet/default_filter.rb', line 25

def initialize(expression:, scope: nil, payload: {})
  @expression = expression
  @scope = scope
  @payload = payload
end

Instance Attribute Details

#expressionString (readonly)

Returns CEL expression to evaluate.

Returns:

  • (String)

    CEL expression to evaluate



14
15
16
# File 'lib/hatchet/default_filter.rb', line 14

def expression
  @expression
end

#payloadHash (readonly)

Returns Static payload for the filter.

Returns:

  • (Hash)

    Static payload for the filter



20
21
22
# File 'lib/hatchet/default_filter.rb', line 20

def payload
  @payload
end

#scopeString? (readonly)

Returns Scope for filter matching.

Returns:

  • (String, nil)

    Scope for filter matching



17
18
19
# File 'lib/hatchet/default_filter.rb', line 17

def scope
  @scope
end

Instance Method Details

#to_hHash

Returns:

  • (Hash)


32
33
34
35
36
# File 'lib/hatchet/default_filter.rb', line 32

def to_h
  h = { expression: @expression, payload: @payload }
  h[:scope] = @scope if @scope
  h
end

#to_protoV1::DefaultFilter

Convert to a V1::DefaultFilter protobuf message

Returns:



40
41
42
43
44
45
46
47
# File 'lib/hatchet/default_filter.rb', line 40

def to_proto
  payload_bytes = JSON.generate(@payload || {}).encode("UTF-8")

  args = { expression: @expression, payload: payload_bytes }
  args[:scope] = @scope if @scope

  ::V1::DefaultFilter.new(**args)
end