Module: EventEngine::EventDefinition::Schemas::ClassMethods

Defined in:
lib/event_engine/event_definition/schemas.rb

Instance Method Summary collapse

Instance Method Details

#schemaSchema

Builds and returns a Schema from this definition’s DSL declarations.

Returns:

Raises:

  • (ArgumentError)

    if the definition has validation errors



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/event_engine/event_definition/schemas.rb', line 79

def schema
  errors = schema_errors
  raise ArgumentError, errors.join(", ") if errors.any?

  required = inputs.select { |_, v| v== :required }.keys
  optional = inputs.select { |_, v| v== :optional }.keys

  Schema.new(
    event_name: @event_name,
    event_type: @event_type,
    process_type: @process_type,
    subject: @subject,
    domain: @domain,
    required_inputs: required,
    optional_inputs: optional,
    payload_fields: payload_fields
  )
end

#schema_errorsArray<String>

Returns validation errors for this definition, if any.

Returns:

  • (Array<String>)


101
102
103
104
105
106
107
# File 'lib/event_engine/event_definition/schemas.rb', line 101

def schema_errors
  errors = []
  validate_identity(errors)
  validate_process_type(errors)
  validate_payload_fields(errors)
  errors
end

#valid_schema?Boolean

Whether this definition has a valid schema (no errors).

Returns:

  • (Boolean)


112
113
114
# File 'lib/event_engine/event_definition/schemas.rb', line 112

def valid_schema?
  schema_errors.empty?
end