Class: Gapic::Schema::Field
- Extended by:
- Forwardable
- Defined in:
- lib/gapic/schema/wrappers.rb
Overview
Wrapper for a protobuf Field.
Instance Attribute Summary collapse
-
#enum ⇒ Object
@ return [Enum | nil] The enum if the field is an enum, nil otherwise.
-
#message ⇒ Object
@ return [Message | nil] The message if the field is a message, nil otherwise.
Attributes inherited from Proto
#address, #descriptor, #docs, #parent
Instance Method Summary collapse
-
#default_value ⇒ String
For numeric types, contains the original text representation of the value.
-
#enum? ⇒ Boolean
Whether this field is an enum.
-
#field_behavior ⇒ Array<Google::Api::FieldBehavior>
A designation of a specific field behavior (required, output only, etc.) in protobuf messages.
-
#immutable? ⇒ Boolean
Denotes a field as immutable.
-
#initialize(descriptor, address, docs, message, enum) ⇒ Field
constructor
Initializes a message object.
-
#input_only? ⇒ Boolean
Denotes a field as input only.
-
#json_name ⇒ String
JSON name of this field.
-
#label ⇒ Google::Protobuf::FieldDescriptorProto::Label
The label of the field.
-
#map? ⇒ Boolean
Whether this field is a map.
-
#message? ⇒ Boolean
Whether this field is a message.
-
#name ⇒ String
The unqualified name of the field.
-
#number ⇒ Integer
The number of the field.
-
#oneof_index ⇒ Integer
If set, gives the index of a oneof in the containing type's oneof_decl list.
-
#optional? ⇒ Boolean
Specifically denotes a field as optional.
-
#options ⇒ Google::Protobuf::FieldOptions
The options of this field.
-
#output_only? ⇒ Boolean
Denotes a field as output only.
-
#repeated? ⇒ Boolean
Whether this field is a repeated field.
-
#required? ⇒ Boolean
Denotes a field as required.
-
#resource_reference ⇒ String
A reference to another resource message or resource definition.
-
#type ⇒ Google::Protobuf::FieldDescriptorProto::Type
If type_name is set, this need not be set.
-
#type_name ⇒ String
For message and enum types, this is the name of the type.
Methods inherited from Proto
#containing_api, #containing_file, #docs_leading_comments, #leading_comments, #leading_detached_comments, #path, #span, #trailing_comments
Constructor Details
#initialize(descriptor, address, docs, message, enum) ⇒ Field
Initializes a message object.
602 603 604 605 606 |
# File 'lib/gapic/schema/wrappers.rb', line 602 def initialize descriptor, address, docs, , enum super descriptor, address, docs = @enum = enum end |
Instance Attribute Details
#enum ⇒ Object
@ return [Enum | nil] The enum if the field is an enum, nil otherwise.
586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 |
# File 'lib/gapic/schema/wrappers.rb', line 586 class Field < Proto extend Forwardable attr_reader :message, :enum attr_writer :message, :enum # Initializes a message object. # @param descriptor [Google::Protobuf::FieldDescriptorProto] the # protobuf representation of this service. # @param address [Enumerable<String>] The address of the proto. See # #address for more info. # @param docs [Google::Protobuf::SourceCodeInfo::Location] The docs # of the proto. See #docs for more info. # @param message [Message | nil] The message if the field is a message, # nil otherwise. # @param enum [Enum | nil] The enum if the field is an enum, nil # otherwise. def initialize descriptor, address, docs, , enum super descriptor, address, docs = @enum = enum end # Whether this field is a message. # @return [Boolean] def return true if false end # Whether this field is a repeated field. # @return [Boolean] def repeated? label == Google::Protobuf::FieldDescriptorProto::Label::LABEL_REPEATED end # Whether this field is an enum. # @return [Boolean] def enum? return true if @enum false end # Whether this field is a map # @return [Boolean] def map? return true if repeated? && &.map_entry? false end # @return [String] A reference to another resource message or resource # definition. See `google/api/resource.proto`. def resource_reference [:".google.api.resource_reference"] if end # @return [Array<Google::Api::FieldBehavior>] A designation of a # specific field behavior (required, output only, etc.) in protobuf # messages. def field_behavior return [:".google.api.field_behavior"] if [] end # Specifically denotes a field as optional. While all fields in protocol # buffers are optional, this may be specified for emphasis if # appropriate. def optional? field_behavior.include? Google::Api::FieldBehavior::OPTIONAL end # Denotes a field as required. This indicates that the field **must** be # provided as part of the request, and failure to do so will cause an # error (usually `INVALID_ARGUMENT`). def required? field_behavior.include? Google::Api::FieldBehavior::REQUIRED end # Denotes a field as output only. This indicates that the field is # provided in responses, but including the field in a request does # nothing (the server *must* ignore it and *must not* throw an error as # a result of the field's presence). def output_only? field_behavior.include? Google::Api::FieldBehavior::OUTPUT_ONLY end # Denotes a field as input only. This indicates that the field is # provided in requests, and the corresponding field is not included in # output. def input_only? field_behavior.include? Google::Api::FieldBehavior::INPUT_ONLY end # Denotes a field as immutable. This indicates that the field may be set # once in a request to create a resource, but may not be changed # thereafter. def immutable? field_behavior.include? Google::Api::FieldBehavior::IMMUTABLE end # @!method name # @return [String] the unqualified name of the field. # @!method number # @return [Integer] the number of the field. # @!method label # @return [Google::Protobuf::FieldDescriptorProto::Label] # The label of the field. # @!method type # @return [Google::Protobuf::FieldDescriptorProto::Type] # If type_name is set, this need not be set. If both this and # type_name are set, this must be one of TYPE_ENUM, TYPE_MESSAGE or # TYPE_GROUP. # @!method type_name # @return [String] # For message and enum types, this is the name of the type. If the # name starts with a '.', it is fully-qualified. Otherwise, # C++-like scoping rules are used to find the type (i.e. first the # nested types within this message are searched, then within the # parent, on up to the root namespace). # @!method default_value # @return [String] # For numeric types, contains the original text representation of # the value. For booleans, "true" or "false". For strings, contains # the default text contents (not escaped in any way). For bytes, # contains the C escaped value. All bytes >= 128 are escaped. # @!method oneof_index # @return [Integer] # If set, gives the index of a oneof in the containing type's # oneof_decl list. This field is a member of that oneof. # @!method json_name # @return [String] # JSON name of this field. The value is set by protocol compiler. If # the user has set a "json_name" option on this field, that option's # value will be used. Otherwise, it's deduced from the field's name # by converting it to camelCase. # @!method options # @return [Google::Protobuf::FieldOptions] the options of this field. def_delegators( :descriptor, :name, :number, :label, :type, :type_name, :default_value, :oneof_index, :json_name, :options ) end |
#message ⇒ Object
@ return [Message | nil] The message if the field is a message, nil otherwise.
586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 |
# File 'lib/gapic/schema/wrappers.rb', line 586 class Field < Proto extend Forwardable attr_reader :message, :enum attr_writer :message, :enum # Initializes a message object. # @param descriptor [Google::Protobuf::FieldDescriptorProto] the # protobuf representation of this service. # @param address [Enumerable<String>] The address of the proto. See # #address for more info. # @param docs [Google::Protobuf::SourceCodeInfo::Location] The docs # of the proto. See #docs for more info. # @param message [Message | nil] The message if the field is a message, # nil otherwise. # @param enum [Enum | nil] The enum if the field is an enum, nil # otherwise. def initialize descriptor, address, docs, , enum super descriptor, address, docs = @enum = enum end # Whether this field is a message. # @return [Boolean] def return true if false end # Whether this field is a repeated field. # @return [Boolean] def repeated? label == Google::Protobuf::FieldDescriptorProto::Label::LABEL_REPEATED end # Whether this field is an enum. # @return [Boolean] def enum? return true if @enum false end # Whether this field is a map # @return [Boolean] def map? return true if repeated? && &.map_entry? false end # @return [String] A reference to another resource message or resource # definition. See `google/api/resource.proto`. def resource_reference [:".google.api.resource_reference"] if end # @return [Array<Google::Api::FieldBehavior>] A designation of a # specific field behavior (required, output only, etc.) in protobuf # messages. def field_behavior return [:".google.api.field_behavior"] if [] end # Specifically denotes a field as optional. While all fields in protocol # buffers are optional, this may be specified for emphasis if # appropriate. def optional? field_behavior.include? Google::Api::FieldBehavior::OPTIONAL end # Denotes a field as required. This indicates that the field **must** be # provided as part of the request, and failure to do so will cause an # error (usually `INVALID_ARGUMENT`). def required? field_behavior.include? Google::Api::FieldBehavior::REQUIRED end # Denotes a field as output only. This indicates that the field is # provided in responses, but including the field in a request does # nothing (the server *must* ignore it and *must not* throw an error as # a result of the field's presence). def output_only? field_behavior.include? Google::Api::FieldBehavior::OUTPUT_ONLY end # Denotes a field as input only. This indicates that the field is # provided in requests, and the corresponding field is not included in # output. def input_only? field_behavior.include? Google::Api::FieldBehavior::INPUT_ONLY end # Denotes a field as immutable. This indicates that the field may be set # once in a request to create a resource, but may not be changed # thereafter. def immutable? field_behavior.include? Google::Api::FieldBehavior::IMMUTABLE end # @!method name # @return [String] the unqualified name of the field. # @!method number # @return [Integer] the number of the field. # @!method label # @return [Google::Protobuf::FieldDescriptorProto::Label] # The label of the field. # @!method type # @return [Google::Protobuf::FieldDescriptorProto::Type] # If type_name is set, this need not be set. If both this and # type_name are set, this must be one of TYPE_ENUM, TYPE_MESSAGE or # TYPE_GROUP. # @!method type_name # @return [String] # For message and enum types, this is the name of the type. If the # name starts with a '.', it is fully-qualified. Otherwise, # C++-like scoping rules are used to find the type (i.e. first the # nested types within this message are searched, then within the # parent, on up to the root namespace). # @!method default_value # @return [String] # For numeric types, contains the original text representation of # the value. For booleans, "true" or "false". For strings, contains # the default text contents (not escaped in any way). For bytes, # contains the C escaped value. All bytes >= 128 are escaped. # @!method oneof_index # @return [Integer] # If set, gives the index of a oneof in the containing type's # oneof_decl list. This field is a member of that oneof. # @!method json_name # @return [String] # JSON name of this field. The value is set by protocol compiler. If # the user has set a "json_name" option on this field, that option's # value will be used. Otherwise, it's deduced from the field's name # by converting it to camelCase. # @!method options # @return [Google::Protobuf::FieldOptions] the options of this field. def_delegators( :descriptor, :name, :number, :label, :type, :type_name, :default_value, :oneof_index, :json_name, :options ) end |
Instance Method Details
#default_value ⇒ String
Returns For numeric types, contains the original text representation of the value. For booleans, "true" or "false". For strings, contains the default text contents (not escaped in any way). For bytes, contains the C escaped value. All bytes >= 128 are escaped.
726 727 728 729 730 731 732 733 734 735 736 737 |
# File 'lib/gapic/schema/wrappers.rb', line 726 def_delegators( :descriptor, :name, :number, :label, :type, :type_name, :default_value, :oneof_index, :json_name, :options ) |
#enum? ⇒ Boolean
Whether this field is an enum.
624 625 626 627 628 |
# File 'lib/gapic/schema/wrappers.rb', line 624 def enum? return true if @enum false end |
#field_behavior ⇒ Array<Google::Api::FieldBehavior>
Returns A designation of a specific field behavior (required, output only, etc.) in protobuf messages.
647 648 649 650 651 |
# File 'lib/gapic/schema/wrappers.rb', line 647 def field_behavior return [:".google.api.field_behavior"] if [] end |
#immutable? ⇒ Boolean
Denotes a field as immutable. This indicates that the field may be set once in a request to create a resource, but may not be changed thereafter.
685 686 687 |
# File 'lib/gapic/schema/wrappers.rb', line 685 def immutable? field_behavior.include? Google::Api::FieldBehavior::IMMUTABLE end |
#input_only? ⇒ Boolean
Denotes a field as input only. This indicates that the field is provided in requests, and the corresponding field is not included in output.
678 679 680 |
# File 'lib/gapic/schema/wrappers.rb', line 678 def input_only? field_behavior.include? Google::Api::FieldBehavior::INPUT_ONLY end |
#json_name ⇒ String
Returns JSON name of this field. The value is set by protocol compiler. If the user has set a "json_name" option on this field, that option's value will be used. Otherwise, it's deduced from the field's name by converting it to camelCase.
726 727 728 729 730 731 732 733 734 735 736 737 |
# File 'lib/gapic/schema/wrappers.rb', line 726 def_delegators( :descriptor, :name, :number, :label, :type, :type_name, :default_value, :oneof_index, :json_name, :options ) |
#label ⇒ Google::Protobuf::FieldDescriptorProto::Label
Returns The label of the field.
726 727 728 729 730 731 732 733 734 735 736 737 |
# File 'lib/gapic/schema/wrappers.rb', line 726 def_delegators( :descriptor, :name, :number, :label, :type, :type_name, :default_value, :oneof_index, :json_name, :options ) |
#map? ⇒ Boolean
Whether this field is a map
632 633 634 635 636 |
# File 'lib/gapic/schema/wrappers.rb', line 632 def map? return true if repeated? && &.map_entry? false end |
#message? ⇒ Boolean
Whether this field is a message.
610 611 612 613 614 |
# File 'lib/gapic/schema/wrappers.rb', line 610 def return true if false end |
#name ⇒ String
Returns the unqualified name of the field.
726 727 728 729 730 731 732 733 734 735 736 737 |
# File 'lib/gapic/schema/wrappers.rb', line 726 def_delegators( :descriptor, :name, :number, :label, :type, :type_name, :default_value, :oneof_index, :json_name, :options ) |
#number ⇒ Integer
Returns the number of the field.
726 727 728 729 730 731 732 733 734 735 736 737 |
# File 'lib/gapic/schema/wrappers.rb', line 726 def_delegators( :descriptor, :name, :number, :label, :type, :type_name, :default_value, :oneof_index, :json_name, :options ) |
#oneof_index ⇒ Integer
Returns If set, gives the index of a oneof in the containing type's oneof_decl list. This field is a member of that oneof.
726 727 728 729 730 731 732 733 734 735 736 737 |
# File 'lib/gapic/schema/wrappers.rb', line 726 def_delegators( :descriptor, :name, :number, :label, :type, :type_name, :default_value, :oneof_index, :json_name, :options ) |
#optional? ⇒ Boolean
Specifically denotes a field as optional. While all fields in protocol buffers are optional, this may be specified for emphasis if appropriate.
656 657 658 |
# File 'lib/gapic/schema/wrappers.rb', line 656 def optional? field_behavior.include? Google::Api::FieldBehavior::OPTIONAL end |
#options ⇒ Google::Protobuf::FieldOptions
Returns the options of this field.
726 727 728 729 730 731 732 733 734 735 736 737 |
# File 'lib/gapic/schema/wrappers.rb', line 726 def_delegators( :descriptor, :name, :number, :label, :type, :type_name, :default_value, :oneof_index, :json_name, :options ) |
#output_only? ⇒ Boolean
Denotes a field as output only. This indicates that the field is provided in responses, but including the field in a request does nothing (the server must ignore it and must not throw an error as a result of the field's presence).
671 672 673 |
# File 'lib/gapic/schema/wrappers.rb', line 671 def output_only? field_behavior.include? Google::Api::FieldBehavior::OUTPUT_ONLY end |
#repeated? ⇒ Boolean
Whether this field is a repeated field.
618 619 620 |
# File 'lib/gapic/schema/wrappers.rb', line 618 def repeated? label == Google::Protobuf::FieldDescriptorProto::Label::LABEL_REPEATED end |
#required? ⇒ Boolean
Denotes a field as required. This indicates that the field must be
provided as part of the request, and failure to do so will cause an
error (usually INVALID_ARGUMENT).
663 664 665 |
# File 'lib/gapic/schema/wrappers.rb', line 663 def required? field_behavior.include? Google::Api::FieldBehavior::REQUIRED end |
#resource_reference ⇒ String
Returns A reference to another resource message or resource
definition. See google/api/resource.proto.
640 641 642 |
# File 'lib/gapic/schema/wrappers.rb', line 640 def resource_reference [:".google.api.resource_reference"] if end |
#type ⇒ Google::Protobuf::FieldDescriptorProto::Type
Returns If type_name is set, this need not be set. If both this and type_name are set, this must be one of TYPE_ENUM, TYPE_MESSAGE or TYPE_GROUP.
726 727 728 729 730 731 732 733 734 735 736 737 |
# File 'lib/gapic/schema/wrappers.rb', line 726 def_delegators( :descriptor, :name, :number, :label, :type, :type_name, :default_value, :oneof_index, :json_name, :options ) |
#type_name ⇒ String
Returns For message and enum types, this is the name of the type. If the name starts with a '.', it is fully-qualified. Otherwise, C++-like scoping rules are used to find the type (i.e. first the nested types within this message are searched, then within the parent, on up to the root namespace).
726 727 728 729 730 731 732 733 734 735 736 737 |
# File 'lib/gapic/schema/wrappers.rb', line 726 def_delegators( :descriptor, :name, :number, :label, :type, :type_name, :default_value, :oneof_index, :json_name, :options ) |