Class: Gapic::Presenters::FieldPresenter
Overview
A presenter for proto fields.
Instance Attribute Summary collapse
Instance Method Summary
collapse
#ensure_absolute_namespace, #fix_namespace, #ruby_namespace, #ruby_namespace_for_address
Constructor Details
#initialize(api, message, field) ⇒ FieldPresenter
Returns a new instance of FieldPresenter.
36
37
38
39
40
41
|
# File 'lib/gapic/presenters/field_presenter.rb', line 36
def initialize api, message, field
@api = api
@message = message
@field = field
@type = "field"
end
|
Instance Attribute Details
#type ⇒ String
Returns String representation of this presenter type.
29
30
31
|
# File 'lib/gapic/presenters/field_presenter.rb', line 29
def type
@type
end
|
Instance Method Details
#as_kwarg(value: nil) ⇒ Object
85
86
87
|
# File 'lib/gapic/presenters/field_presenter.rb', line 85
def as_kwarg value: nil
"#{name}: #{value || value_name}"
end
|
#camel_name ⇒ String
Name of this field, camel-cased.
156
157
158
|
# File 'lib/gapic/presenters/field_presenter.rb', line 156
def camel_name
camel_name_for name
end
|
#default_value ⇒ Object
79
80
81
82
83
|
# File 'lib/gapic/presenters/field_presenter.rb', line 79
def default_value
single = default_singular_value
return "[#{single}]" if @field.repeated? && !@field.map?
single
end
|
#default_value_for_type ⇒ String?
Returns a stringified default value for the protobuf types
that are possible to fit into the query string parameter
and nil for the other types (e.g. Messages)
138
139
140
141
142
143
144
145
146
147
148
149
150
|
# File 'lib/gapic/presenters/field_presenter.rb', line 138
def default_value_for_type
if @field.message?
nil
elsif @field.enum?
":#{@field.enum.values.first.name}"
else
case @field.type
when 1, 2, 3, 4, 5, 6, 7, 13, 15, 16, 17, 18 then "0"
when 9, 12 then "\"\""
when 8 then "false"
end
end
end
|
#doc_attribute_type ⇒ Object
59
60
61
62
|
# File 'lib/gapic/presenters/field_presenter.rb', line 59
def doc_attribute_type
mode = @field.output_only? ? "r" : "rw"
"@!attribute [#{mode}] #{@field.name}"
end
|
#doc_description(transport: nil, is_rpc_param: false) ⇒ String
The description as it should appear in YARD docs.
75
76
77
|
# File 'lib/gapic/presenters/field_presenter.rb', line 75
def doc_description transport: nil, is_rpc_param: false
@field. transport: transport, is_rpc_param: is_rpc_param
end
|
#doc_types ⇒ Object
55
56
57
|
# File 'lib/gapic/presenters/field_presenter.rb', line 55
def doc_types
field_doc_types @field, false
end
|
#enum? ⇒ Boolean
103
104
105
|
# File 'lib/gapic/presenters/field_presenter.rb', line 103
def enum?
@field.enum?
end
|
#is_deprecated? ⇒ Boolean
Returns Whether the field is marked as deprecated.
163
164
165
|
# File 'lib/gapic/presenters/field_presenter.rb', line 163
def is_deprecated?
@field.is_deprecated?
end
|
#map? ⇒ Boolean
119
120
121
|
# File 'lib/gapic/presenters/field_presenter.rb', line 119
def map?
@field.map?
end
|
#message? ⇒ Boolean
99
100
101
|
# File 'lib/gapic/presenters/field_presenter.rb', line 99
def message?
@field.message?
end
|
#name ⇒ Object
43
44
45
|
# File 'lib/gapic/presenters/field_presenter.rb', line 43
def name
@field.name
end
|
#oneof? ⇒ Boolean
123
124
125
|
# File 'lib/gapic/presenters/field_presenter.rb', line 123
def oneof?
@field.oneof?
end
|
#oneof_name ⇒ Object
127
128
129
|
# File 'lib/gapic/presenters/field_presenter.rb', line 127
def oneof_name
@message.oneof_decl[@field.oneof_index].name
end
|
#output_doc_types ⇒ Object
64
65
66
|
# File 'lib/gapic/presenters/field_presenter.rb', line 64
def output_doc_types
field_doc_types @field, true
end
|
#proto3_optional? ⇒ Boolean
107
108
109
|
# File 'lib/gapic/presenters/field_presenter.rb', line 107
def proto3_optional?
@field.proto3_optional?
end
|
#repeated? ⇒ Boolean
111
112
113
|
# File 'lib/gapic/presenters/field_presenter.rb', line 111
def repeated?
@field.repeated?
end
|
#required? ⇒ Boolean
115
116
117
|
# File 'lib/gapic/presenters/field_presenter.rb', line 115
def required?
@field.required?
end
|
#type_name ⇒ Object
TODO: remove, only used in tests
90
91
92
|
# File 'lib/gapic/presenters/field_presenter.rb', line 90
def type_name
@field.type_name
end
|
#type_name_full ⇒ Object
94
95
96
97
|
# File 'lib/gapic/presenters/field_presenter.rb', line 94
def type_name_full
return nil if type_name.blank?
ruby_namespace @api, type_name
end
|
#value_name ⇒ String
Returns The field name to be used as a value without reserved keywords.
50
51
52
53
|
# File 'lib/gapic/presenters/field_presenter.rb', line 50
def value_name
name = @field.name
Gapic::RubyInfo.keywords.include?(name) ? "#{name}_param" : name
end
|