module Protobuf::Optionable::ClassMethods
Public Instance Methods
get_option(name)
click to toggle source
# File lib/protobuf/optionable.rb, line 4 def get_option(name) name = name.to_s option = optionable_descriptor_class.get_field(name, true) fail ArgumentError, "invalid option=#{name}" unless option unless option.fully_qualified_name.to_s == name # Eventually we'll deprecate the use of simple names of fields completely, but for now make sure people # are accessing options correctly. We allow simple names in other places for backwards compatibility. fail ArgumentError, "must access option using its fully qualified name: #{option.fully_qualified_name.inspect}" end value = if @_optionable_options.try(:key?, name) @_optionable_options[name] else option.default_value end if option.type_class < ::Protobuf::Message option.type_class.new(value) else value end end
get_option!(name)
click to toggle source
# File lib/protobuf/optionable.rb, line 26 def get_option!(name) get_option(name) if @_optionable_options.try(:key?, name.to_s) end
Private Instance Methods
set_option(name, value = true)
click to toggle source
# File lib/protobuf/optionable.rb, line 32 def set_option(name, value = true) @_optionable_options ||= {} @_optionable_options[name.to_s] = value end