Class: EventEngine::EventDefinition::Schemas::Schema
- Inherits:
-
Struct
- Object
- Struct
- EventEngine::EventDefinition::Schemas::Schema
- Defined in:
- lib/event_engine/event_definition/schemas.rb
Instance Attribute Summary collapse
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#event_name ⇒ Object
Returns the value of attribute event_name.
-
#event_type ⇒ Object
Returns the value of attribute event_type.
-
#event_version ⇒ Object
Returns the value of attribute event_version.
-
#optional_inputs ⇒ Object
Returns the value of attribute optional_inputs.
-
#payload_fields ⇒ Object
Returns the value of attribute payload_fields.
-
#required_inputs ⇒ Object
Returns the value of attribute required_inputs.
-
#subject ⇒ Object
Returns the value of attribute subject.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#domain ⇒ Object
Returns the value of attribute domain
11 12 13 |
# File 'lib/event_engine/event_definition/schemas.rb', line 11 def domain @domain end |
#event_name ⇒ Object
Returns the value of attribute event_name
11 12 13 |
# File 'lib/event_engine/event_definition/schemas.rb', line 11 def event_name @event_name end |
#event_type ⇒ Object
Returns the value of attribute event_type
11 12 13 |
# File 'lib/event_engine/event_definition/schemas.rb', line 11 def event_type @event_type end |
#event_version ⇒ Object
Returns the value of attribute event_version
11 12 13 |
# File 'lib/event_engine/event_definition/schemas.rb', line 11 def event_version @event_version end |
#optional_inputs ⇒ Object
Returns the value of attribute optional_inputs
11 12 13 |
# File 'lib/event_engine/event_definition/schemas.rb', line 11 def optional_inputs @optional_inputs end |
#payload_fields ⇒ Object
Returns the value of attribute payload_fields
11 12 13 |
# File 'lib/event_engine/event_definition/schemas.rb', line 11 def payload_fields @payload_fields end |
#required_inputs ⇒ Object
Returns the value of attribute required_inputs
11 12 13 |
# File 'lib/event_engine/event_definition/schemas.rb', line 11 def required_inputs @required_inputs end |
#subject ⇒ Object
Returns the value of attribute subject
11 12 13 |
# File 'lib/event_engine/event_definition/schemas.rb', line 11 def subject @subject end |
Class Method Details
.from_h(hash) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/event_engine/event_definition/schemas.rb', line 23 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
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/event_engine/event_definition/schemas.rb', line 38 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
#fingerprint ⇒ Object
49 50 51 52 53 |
# File 'lib/event_engine/event_definition/schemas.rb', line 49 def fingerprint Digest::SHA256.hexdigest( canonical_representation ) end |
#to_h ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/event_engine/event_definition/schemas.rb', line 55 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 |
#to_ruby ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/event_engine/event_definition/schemas.rb', line 69 def to_ruby <<~RUBY.strip EventEngine::EventDefinition::Schema.new( event_name: #{event_name.inspect}, event_version: #{event_version.inspect}, event_type: #{event_type.inspect}, subject: #{subject.inspect}, domain: #{domain.inspect}, required_inputs: #{required_inputs.inspect}, optional_inputs: #{optional_inputs.inspect}, payload_fields: [#{payload_fields.map { |h| ruby_hash(h) }.join(", ")}] ) RUBY end |