Class: Protobuf::Field::FieldProxy
- Inherits:
-
Object
- Object
- Protobuf::Field::FieldProxy
- Defined in:
- lib/protobuf/message/field.rb
Instance Method Summary collapse
-
#initialize(message_class, rule, type, name, tag, opts = {}) ⇒ FieldProxy
constructor
A new instance of FieldProxy.
- #ready? ⇒ Boolean
- #setup ⇒ Object
- #typename_to_class(message_class, type) ⇒ Object
Constructor Details
#initialize(message_class, rule, type, name, tag, opts = {}) ⇒ FieldProxy
Returns a new instance of FieldProxy.
196 197 198 199 |
# File 'lib/protobuf/message/field.rb', line 196 def initialize(, rule, type, name, tag, opts={}) @message_class, @rule, @type, @name, @tag, @opts = , rule, type, name, tag, opts end |
Instance Method Details
#ready? ⇒ Boolean
201 |
# File 'lib/protobuf/message/field.rb', line 201 def ready?; false end |
#setup ⇒ Object
203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/protobuf/message/field.rb', line 203 def setup type = typename_to_class @message_class, @type field_class = if type.superclass == Protobuf::Enum Protobuf::Field::EnumField elsif type.superclass == Protobuf::Message Protobuf::Field::MessageField else raise TypeError.new(type.inspect) end field_class.new @message_class, @rule, type, @name, @tag, @opts end |
#typename_to_class(message_class, type) ⇒ Object
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/protobuf/message/field.rb', line 216 def typename_to_class(, type) suffix = type.to_s.split('::') modules = .to_s.split('::') args = (Object.method(:const_defined?).arity == 1) ? [] : [nil, false] while mod = modules.empty? ? Object : eval(modules.join('::')) mod = suffix.inject(mod) {|m, s| args[0] = s m and m.const_defined?(*args) and m.const_get(s) } break if mod raise NameError.new("type not found: #{type}", type) if modules.empty? modules.pop end mod end |