class RabbitFeed::EventDefinitions::Event
Attributes
definition[R]
fields[R]
name[R]
sensitive_fields[R]
version[R]
Public Class Methods
new(name, version)
click to toggle source
# File lib/rabbit_feed/event_definitions.rb, line 35 def initialize(name, version) @name = name @version = version @fields = [] @sensitive_fields = [] end
Public Instance Methods
defined_as() { || ... }
click to toggle source
# File lib/rabbit_feed/event_definitions.rb, line 51 def defined_as(&block) @definition = yield if block.present? end
event_schema()
click to toggle source
# File lib/rabbit_feed/event_definitions.rb, line 71 def event_schema [ { name: 'payload', type: payload_schema, doc: 'The event payload (defined by the source system)' }, { name: 'metadata', type: metadata_schema, doc: 'The event metadata (defined by rabbit feed)' } ] end
field(name, options)
click to toggle source
# File lib/rabbit_feed/event_definitions.rb, line 46 def field(name, options) sensitive_fields << name.to_s if options.delete(:sensitive) fields << (Field.new name, options[:type], options[:definition]) end
metadata_schema()
click to toggle source
# File lib/rabbit_feed/event_definitions.rb, line 59 def metadata_schema { name: 'event_metadata', type: 'record', fields: [ (Field.new 'application', 'string', 'The name of the application that created the event'), (Field.new 'host', 'string', 'The hostname of the server on which the event was created'), (Field.new 'environment', 'string', 'The environment in which the event was created'), (Field.new 'version', 'string', 'The version of the event payload'), (Field.new 'schema_version', 'string', 'The version of the event schema'), (Field.new 'name', 'string', 'The name of the event'), (Field.new 'created_at_utc', 'string', 'The UTC time that the event was created') ].map(&:schema) } end
payload_contains(&block)
click to toggle source
# File lib/rabbit_feed/event_definitions.rb, line 42 def payload_contains(&block) instance_eval(&block) end
payload_schema()
click to toggle source
# File lib/rabbit_feed/event_definitions.rb, line 55 def payload_schema { name: "#{name}_payload", type: 'record', fields: fields.map(&:schema) } end
schema()
click to toggle source
# File lib/rabbit_feed/event_definitions.rb, line 78 def schema @schema ||= Avro::Schema.parse({ name: name, type: 'record', doc: definition, fields: event_schema }.to_json) end
validate!()
click to toggle source
# File lib/rabbit_feed/event_definitions.rb, line 82 def validate! raise ConfigurationError, "Bad event specification for #{name}: #{errors.messages}" if invalid? end
Private Instance Methods
schema_parseable()
click to toggle source
# File lib/rabbit_feed/event_definitions.rb, line 88 def schema_parseable schema rescue => e errors.add(:fields, "could not be parsed into a schema, reason: #{e.message}") end