Class: RFlow::Message::Data
- Inherits:
-
Object
- Object
- RFlow::Message::Data
- Defined in:
- lib/rflow/message.rb
Overview
Should proxy most methods to data_object that we can serialize to avro using the schema. Extensions should use ‘extended’ hook to apply immediate changes.
Instance Attribute Summary collapse
-
#data_object ⇒ Object
Returns the value of attribute data_object.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
-
#schema_string ⇒ Object
readonly
Returns the value of attribute schema_string.
-
#serialization_type ⇒ Object
readonly
Returns the value of attribute serialization_type.
Instance Method Summary collapse
-
#initialize(schema_string, serialization_type = 'avro', serialized_data = nil) ⇒ Data
constructor
A new instance of Data.
-
#method_missing(method_sym, *args, &block) ⇒ Object
Proxy methods down to the underlying data_object, probably a Hash.
- #to_avro ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(schema_string, serialization_type = 'avro', serialized_data = nil) ⇒ Data
Returns a new instance of Data.
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/rflow/message.rb', line 136 def initialize(schema_string, serialization_type = 'avro', serialized_data = nil) raise ArgumentError, 'Only Avro serialization_type supported at the moment' unless serialization_type.to_s == 'avro' @schema_string = schema_string @serialization_type = serialization_type.to_s begin @schema = ::Avro::Schema.parse(schema_string) @writer = ::Avro::IO::DatumWriter.new(@schema) rescue Exception => e raise ArgumentError, "Invalid schema '#{@schema_string}': #{e}: #{e.}" end if serialized_data serialized_data.force_encoding 'BINARY' @data_object = RFlow::Avro.decode(::Avro::IO::DatumReader.new(schema, schema), serialized_data) end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_sym, *args, &block) ⇒ Object
Proxy methods down to the underlying data_object, probably a Hash. Hopefully an extension will provide any additional functionality so this won’t be called unless needed
166 167 168 |
# File 'lib/rflow/message.rb', line 166 def method_missing(method_sym, *args, &block) @data_object.send(method_sym, *args, &block) end |
Instance Attribute Details
#data_object ⇒ Object
Returns the value of attribute data_object.
134 135 136 |
# File 'lib/rflow/message.rb', line 134 def data_object @data_object end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
133 134 135 |
# File 'lib/rflow/message.rb', line 133 def schema @schema end |
#schema_string ⇒ Object (readonly)
Returns the value of attribute schema_string.
133 134 135 |
# File 'lib/rflow/message.rb', line 133 def schema_string @schema_string end |
#serialization_type ⇒ Object (readonly)
Returns the value of attribute serialization_type.
133 134 135 |
# File 'lib/rflow/message.rb', line 133 def serialization_type @serialization_type end |