Class: RabbitFeed::EventDefinitions::Event
- Inherits:
-
Object
- Object
- RabbitFeed::EventDefinitions::Event
- Includes:
- ActiveModel::Validations
- Defined in:
- lib/rabbit_feed/event_definitions.rb
Instance Attribute Summary collapse
-
#definition ⇒ Object
readonly
Returns the value of attribute definition.
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#sensitive_fields ⇒ Object
readonly
Returns the value of attribute sensitive_fields.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #defined_as(&block) ⇒ Object
- #event_schema ⇒ Object
- #field(name, options) ⇒ Object
-
#initialize(name, version) ⇒ Event
constructor
A new instance of Event.
- #metadata_schema ⇒ Object
- #payload_contains(&block) ⇒ Object
- #payload_schema ⇒ Object
- #schema ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(name, version) ⇒ Event
Returns a new instance of Event.
35 36 37 38 39 40 |
# File 'lib/rabbit_feed/event_definitions.rb', line 35 def initialize(name, version) @name = name @version = version @fields = [] @sensitive_fields = [] end |
Instance Attribute Details
#definition ⇒ Object (readonly)
Returns the value of attribute definition.
30 31 32 |
# File 'lib/rabbit_feed/event_definitions.rb', line 30 def definition @definition end |
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
30 31 32 |
# File 'lib/rabbit_feed/event_definitions.rb', line 30 def fields @fields end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
30 31 32 |
# File 'lib/rabbit_feed/event_definitions.rb', line 30 def name @name end |
#sensitive_fields ⇒ Object (readonly)
Returns the value of attribute sensitive_fields.
30 31 32 |
# File 'lib/rabbit_feed/event_definitions.rb', line 30 def sensitive_fields @sensitive_fields end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
30 31 32 |
# File 'lib/rabbit_feed/event_definitions.rb', line 30 def version @version end |
Instance Method Details
#defined_as(&block) ⇒ Object
51 52 53 |
# File 'lib/rabbit_feed/event_definitions.rb', line 51 def defined_as(&block) @definition = yield if block.present? end |
#event_schema ⇒ Object
71 72 73 74 75 76 |
# 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: , doc: 'The event metadata (defined by rabbit feed)' } ] end |
#field(name, options) ⇒ Object
46 47 48 49 |
# File 'lib/rabbit_feed/event_definitions.rb', line 46 def field(name, ) sensitive_fields << name.to_s if .delete(:sensitive) fields << (Field.new name, [:type], [:definition]) end |
#metadata_schema ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/rabbit_feed/event_definitions.rb', line 59 def { 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) ⇒ Object
42 43 44 |
# File 'lib/rabbit_feed/event_definitions.rb', line 42 def payload_contains(&block) instance_eval(&block) end |
#payload_schema ⇒ Object
55 56 57 |
# File 'lib/rabbit_feed/event_definitions.rb', line 55 def payload_schema { name: "#{name}_payload", type: 'record', fields: fields.map(&:schema) } end |
#schema ⇒ Object
78 79 80 |
# 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! ⇒ Object
82 83 84 |
# File 'lib/rabbit_feed/event_definitions.rb', line 82 def validate! raise ConfigurationError, "Bad event specification for #{name}: #{errors.}" if invalid? end |