Class: AvroPinions::Message
- Inherits:
-
Object
- Object
- AvroPinions::Message
- Defined in:
- lib/avro_pinions/message.rb
Defined Under Namespace
Classes: InvalidRecord
Instance Method Summary collapse
- #avro_schema ⇒ Object
- #codec ⇒ Object
- #encode ⇒ Object
- #namespace ⇒ Object
- #publish ⇒ Object
- #record ⇒ Object
-
#schema ⇒ Object
Schema is inferred to be the .avsc file in the schemas folder with the name as given.
- #topic ⇒ Object
- #valid? ⇒ Boolean
Instance Method Details
#avro_schema ⇒ Object
50 51 52 |
# File 'lib/avro_pinions/message.rb', line 50 def avro_schema @avro_schema ||= AvroPinions.schema_registry.schema(schema, namespace) end |
#codec ⇒ Object
46 47 48 |
# File 'lib/avro_pinions/message.rb', line 46 def codec @codec ||= AvroPinions::Codec.new(avro_schema) end |
#encode ⇒ Object
38 39 40 |
# File 'lib/avro_pinions/message.rb', line 38 def encode codec.encode(record) end |
#namespace ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/avro_pinions/message.rb', line 22 def namespace if defined?(self.class::NAMESPACE) self.class::NAMESPACE else raise AvroPinions::NotFullyImplementedError, 'No Namespace defined' end end |
#publish ⇒ Object
34 35 36 |
# File 'lib/avro_pinions/message.rb', line 34 def publish AvroPinions.publisher.publish(topic, record) end |
#record ⇒ Object
30 31 32 |
# File 'lib/avro_pinions/message.rb', line 30 def record raise AvroPinions::NotFullyImplementedError, 'record method not implemented' end |
#schema ⇒ Object
Schema is inferred to be the .avsc file in the schemas folder with the name as given
14 15 16 17 18 19 20 |
# File 'lib/avro_pinions/message.rb', line 14 def schema if defined?(self.class::SCHEMA) self.class::SCHEMA else raise AvroPinions::NotFullyImplementedError, 'No Schema defined' end end |
#topic ⇒ Object
3 4 5 6 7 8 9 10 |
# File 'lib/avro_pinions/message.rb', line 3 def topic # self.class::SYMBOL looks up a class constant in a child class if defined?(self.class::TOPIC) self.class::TOPIC else raise AvroPinions::NotFullyImplementedError, 'No Topic defined' end end |
#valid? ⇒ Boolean
42 43 44 |
# File 'lib/avro_pinions/message.rb', line 42 def valid? Avro::Schema.validate(avro_schema, AvroPinions::Codec.pedantic_data(record)) end |