module Protobuf::Field
Constants
- PRIMITIVE_FIELD_MAP
Public Class Methods
build(message_class, rule, type, name, tag, simple_name, options = {})
click to toggle source
# File lib/protobuf/field.rb, line 44 def self.build(message_class, rule, type, name, tag, simple_name, options = {}) field_class(type).new(message_class, rule, field_type(type), name, tag, simple_name, options) end
field_class(type)
click to toggle source
Returns the field class for primitives, EnumField for types that inherit from Protobuf::Enum, and MessageField for types that inherit from Protobuf::Message.
# File lib/protobuf/field.rb, line 52 def self.field_class(type) if PRIMITIVE_FIELD_MAP.key?(type) PRIMITIVE_FIELD_MAP[type] elsif type < ::Protobuf::Enum EnumField elsif type < ::Protobuf::Message MessageField elsif type < ::Protobuf::Field::BaseField type else fail ArgumentError, "Invalid field type #{type}" end end
field_type(type)
click to toggle source
Returns the mapped type for primitives, otherwise the given type is returned.
# File lib/protobuf/field.rb, line 69 def self.field_type(type) PRIMITIVE_FIELD_MAP.fetch(type) { type } end