Module: Pb::Serializable::Dsl
- Included in:
- Pb::Serializable
- Defined in:
- lib/pb/serializable/dsl.rb,
lib/pb/serializable/dsl/oneof.rb,
lib/pb/serializable/dsl/attribute.rb
Instance Method Summary collapse
- #attribute(name, opts = {}) ⇒ void
- #ignore(*names) ⇒ void
- #message(klass) ⇒ void
- #oneof(name, allow_nil: false) ⇒ void
Instance Method Details
#attribute(name, opts = {}) ⇒ void
This method returns an undefined value.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/pb/serializable/dsl.rb', line 22 def attribute(name, opts = {}) raise ::Pb::Serializer::MissingMessageTypeError, "message specificaiton is missed" unless fd = .descriptor.find { |fd| fd.name.to_sym == name } raise ::Pb::Serializer::UnknownFieldError, "#{name} is not defined in #{ __pb_serializer_message_class.name}" unless fd attr = Attribute.new( name: name, options: opts, field_descriptor: fd, oneof: @current_oneof&.name, ) __pb_serializer_attr_by_name[name] = attr unless method_defined?(attr.name) define_method attr.name do primary_object.public_send(attr.name) end end end |
#ignore(*names) ⇒ void
This method returns an undefined value.
49 50 51 52 53 |
# File 'lib/pb/serializable/dsl.rb', line 49 def ignore(*names) names.each do |name| attribute name, ignore: true end end |
#message(klass) ⇒ void
This method returns an undefined value.
9 10 11 |
# File 'lib/pb/serializable/dsl.rb', line 9 def (klass) self. = klass end |
#oneof(name, allow_nil: false) ⇒ void
This method returns an undefined value.
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/pb/serializable/dsl.rb', line 63 def oneof(name, allow_nil: false) @current_oneof = Oneof.new( name: name, allow_nil: allow_nil, attributes: [], ) yield __pb_serializer_oneof_by_name[name] = @current_oneof @current_oneof = nil end |