Class: EventEngine::CatalogEntry

Inherits:
Struct
  • Object
show all
Defined in:
lib/event_engine/catalog_entry.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#domainObject

Returns the value of attribute domain

Returns:

  • (Object)

    the current value of domain



5
6
7
# File 'lib/event_engine/catalog_entry.rb', line 5

def domain
  @domain
end

#event_nameObject

Returns the value of attribute event_name

Returns:

  • (Object)

    the current value of event_name



5
6
7
# File 'lib/event_engine/catalog_entry.rb', line 5

def event_name
  @event_name
end

#event_typeObject

Returns the value of attribute event_type

Returns:

  • (Object)

    the current value of event_type



5
6
7
# File 'lib/event_engine/catalog_entry.rb', line 5

def event_type
  @event_type
end

#event_versionObject

Returns the value of attribute event_version

Returns:

  • (Object)

    the current value of event_version



5
6
7
# File 'lib/event_engine/catalog_entry.rb', line 5

def event_version
  @event_version
end

#optional_inputsObject

Returns the value of attribute optional_inputs

Returns:

  • (Object)

    the current value of optional_inputs



5
6
7
# File 'lib/event_engine/catalog_entry.rb', line 5

def optional_inputs
  @optional_inputs
end

#payload_fieldsObject

Returns the value of attribute payload_fields

Returns:

  • (Object)

    the current value of payload_fields



5
6
7
# File 'lib/event_engine/catalog_entry.rb', line 5

def payload_fields
  @payload_fields
end

#required_inputsObject

Returns the value of attribute required_inputs

Returns:

  • (Object)

    the current value of required_inputs



5
6
7
# File 'lib/event_engine/catalog_entry.rb', line 5

def required_inputs
  @required_inputs
end

#subjectObject

Returns the value of attribute subject

Returns:

  • (Object)

    the current value of subject



5
6
7
# File 'lib/event_engine/catalog_entry.rb', line 5

def subject
  @subject
end

Class Method Details

.from_h(hash) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/event_engine/catalog_entry.rb', line 17

def self.from_h(hash)
  h = hash.transform_keys(&:to_sym)

  new(
    event_name: h[:event_name]&.to_sym,
    event_version: h[:event_version],
    event_type: h[:event_type]&.to_sym,
    subject: h[:subject]&.to_sym,
    domain: h[:domain]&.to_sym,
    required_inputs: Array(h[:required_inputs]).map(&:to_sym),
    optional_inputs: Array(h[:optional_inputs]).map(&:to_sym),
    payload_fields: Array(h[:payload_fields]).map { |field| payload_field_from_h(field) }
  )
end

.payload_field_from_h(field) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/event_engine/catalog_entry.rb', line 32

def self.payload_field_from_h(field)
  f = field.transform_keys(&:to_sym)

  {
    name: f[:name]&.to_sym,
    required: f[:required],
    from: f[:from]&.to_sym,
    attr: f[:attr]&.to_sym
  }
end

Instance Method Details

#fingerprintObject



43
44
45
# File 'lib/event_engine/catalog_entry.rb', line 43

def fingerprint
  Digest::SHA256.hexdigest(canonical_representation)
end

#to_hObject



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/event_engine/catalog_entry.rb', line 47

def to_h
  {
    event_name: event_name,
    event_version: event_version,
    event_type: event_type,
    subject: subject,
    domain: domain,
    required_inputs: required_inputs,
    optional_inputs: optional_inputs,
    payload_fields: payload_fields.map { |field| payload_field_h(field) },
    fingerprint: fingerprint
  }
end