Module: Sequel::Plugins::Protobuf::ClassMethods
- Defined in:
- lib/sequel/plugins/protobuf.rb
Overview
When mixed in, this module provides the ability for objects to be serialized from protocol buffer strings
Instance Attribute Summary collapse
-
#protobuf_driver ⇒ Object
readonly
Returns the value of attribute protobuf_driver.
-
#protobuf_model ⇒ Object
readonly
Returns the value of attribute protobuf_model.
Instance Method Summary collapse
-
#from_protobuf(protobuf, options = {}) ⇒ Object
Creates and returns a new instance of the current class from the passed in protobuf message.
Instance Attribute Details
#protobuf_driver ⇒ Object (readonly)
Returns the value of attribute protobuf_driver.
61 62 63 |
# File 'lib/sequel/plugins/protobuf.rb', line 61 def protobuf_driver @protobuf_driver end |
#protobuf_model ⇒ Object (readonly)
Returns the value of attribute protobuf_model.
61 62 63 |
# File 'lib/sequel/plugins/protobuf.rb', line 61 def protobuf_model @protobuf_model end |
Instance Method Details
#from_protobuf(protobuf, options = {}) ⇒ Object
Creates and returns a new instance of the current class from the passed in protobuf message
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/sequel/plugins/protobuf.rb', line 68 def from_protobuf(protobuf, = {}) pb_model = @protobuf_driver.parse(@protobuf_model, protobuf, ) # Coerce data from protobuf array to a new model model = self.send(:new) model.columns.each do |v| if pb_model.respond_to?("#{v}=".to_sym) model.send("#{v}=", pb_model.send(v.to_sym)) end end return model end |