Class: Protobuf::Generators::Base
- Inherits:
-
Object
- Object
- Protobuf::Generators::Base
- Includes:
- Printable
- Defined in:
- lib/protobuf/generators/base.rb
Direct Known Subclasses
EnumGenerator, ExtensionGenerator, FieldGenerator, FileGenerator, MessageGenerator, ServiceGenerator
Constant Summary
Constants included from Printable
Printable::PARENT_CLASS_ENUM, Printable::PARENT_CLASS_MESSAGE, Printable::PARENT_CLASS_SERVICE
Instance Attribute Summary collapse
-
#descriptor ⇒ Object
readonly
Returns the value of attribute descriptor.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #fully_qualified_type_namespace ⇒ Object
-
#initialize(descriptor, indent_level = 0, options = {}) ⇒ Base
constructor
A new instance of Base.
- #run_once(label, &block) ⇒ Object
- #to_s ⇒ Object
- #type_namespace ⇒ Object
Methods included from Printable
Constructor Details
#initialize(descriptor, indent_level = 0, options = {}) ⇒ Base
Returns a new instance of Base.
34 35 36 37 38 39 |
# File 'lib/protobuf/generators/base.rb', line 34 def initialize(descriptor, indent_level = 0, = {}) @descriptor = descriptor @options = @namespace = @options.fetch(:namespace) { [] } init_printer(indent_level) end |
Instance Attribute Details
#descriptor ⇒ Object (readonly)
Returns the value of attribute descriptor.
32 33 34 |
# File 'lib/protobuf/generators/base.rb', line 32 def descriptor @descriptor end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
32 33 34 |
# File 'lib/protobuf/generators/base.rb', line 32 def namespace @namespace end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
32 33 34 |
# File 'lib/protobuf/generators/base.rb', line 32 def @options end |
Class Method Details
.validate_tags(type_name, tags) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/protobuf/generators/base.rb', line 8 def self.(type_name, ) return if .empty? = .uniq if .size < .size ::Protobuf::CodeGenerator.fatal("#{type_name} object has duplicate tags. Expected #{.size} tags, but got #{.size}. Suppress with PB_NO_TAG_WARNINGS=1.") end unless ENV.key?('PB_NO_TAG_WARNINGS') range = (.min)..(.max) if range.respond_to?(:size) expected_size = range.size else expected_size = range.to_a.size end if .size < expected_size ::Protobuf::CodeGenerator.print_tag_warning_suppress ::Protobuf::CodeGenerator.warn("#{type_name} object should have #{expected_size} tags (#{range.begin}..#{range.end}), but found #{.size} tags.") end end end |
Instance Method Details
#fully_qualified_type_namespace ⇒ Object
41 42 43 |
# File 'lib/protobuf/generators/base.rb', line 41 def fully_qualified_type_namespace ".#{type_namespace.join('.')}" end |
#run_once(label, &block) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/protobuf/generators/base.rb', line 45 def run_once(label, &block) tracker_ivar = "@_#{label}_compiled" value_ivar = "@_#{label}_compiled_value" if instance_variable_get(tracker_ivar) return instance_variable_get(value_ivar) else return_value = block.call instance_variable_set(tracker_ivar, true) instance_variable_set(value_ivar, return_value) return return_value end end |
#to_s ⇒ Object
59 60 61 62 |
# File 'lib/protobuf/generators/base.rb', line 59 def to_s compile print_contents # see Printable end |
#type_namespace ⇒ Object
64 65 66 |
# File 'lib/protobuf/generators/base.rb', line 64 def type_namespace @type_namespace ||= @namespace + [ descriptor.name ] end |