Class: Gapic::Presenters::FieldPresenter
Overview
A presenter for proto fields.
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.
28
29
30
31
32
|
# File 'lib/gapic/presenters/field_presenter.rb', line 28
def initialize api, message, field
@api = api
@message = message
@field = field
end
|
Instance Method Details
#as_kwarg(value: nil) ⇒ Object
61
62
63
|
# File 'lib/gapic/presenters/field_presenter.rb', line 61
def as_kwarg value: nil
"#{name}: #{value || name}"
end
|
#camel_name ⇒ String
Name of this field, camel-cased
131
132
133
|
# File 'lib/gapic/presenters/field_presenter.rb', line 131
def camel_name
camel_name_for name
end
|
#default_value ⇒ Object
55
56
57
58
59
|
# File 'lib/gapic/presenters/field_presenter.rb', line 55
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)
114
115
116
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/gapic/presenters/field_presenter.rb', line 114
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
42
43
44
45
|
# File 'lib/gapic/presenters/field_presenter.rb', line 42
def doc_attribute_type
mode = @field.output_only? ? "r" : "rw"
"@!attribute [#{mode}] #{@field.name}"
end
|
#doc_description ⇒ Object
51
52
53
|
# File 'lib/gapic/presenters/field_presenter.rb', line 51
def doc_description
@field.
end
|
#doc_types ⇒ Object
38
39
40
|
# File 'lib/gapic/presenters/field_presenter.rb', line 38
def doc_types
field_doc_types @field, false
end
|
#enum? ⇒ Boolean
79
80
81
|
# File 'lib/gapic/presenters/field_presenter.rb', line 79
def enum?
@field.enum?
end
|
#map? ⇒ Boolean
95
96
97
|
# File 'lib/gapic/presenters/field_presenter.rb', line 95
def map?
@field.map?
end
|
#message? ⇒ Boolean
75
76
77
|
# File 'lib/gapic/presenters/field_presenter.rb', line 75
def message?
@field.message?
end
|
#name ⇒ Object
34
35
36
|
# File 'lib/gapic/presenters/field_presenter.rb', line 34
def name
@field.name
end
|
#oneof? ⇒ Boolean
99
100
101
|
# File 'lib/gapic/presenters/field_presenter.rb', line 99
def oneof?
@field.oneof?
end
|
#oneof_name ⇒ Object
103
104
105
|
# File 'lib/gapic/presenters/field_presenter.rb', line 103
def oneof_name
@message.oneof_decl[@field.oneof_index].name
end
|
#output_doc_types ⇒ Object
47
48
49
|
# File 'lib/gapic/presenters/field_presenter.rb', line 47
def output_doc_types
field_doc_types @field, true
end
|
#proto3_optional? ⇒ Boolean
83
84
85
|
# File 'lib/gapic/presenters/field_presenter.rb', line 83
def proto3_optional?
@field.proto3_optional?
end
|
#repeated? ⇒ Boolean
87
88
89
|
# File 'lib/gapic/presenters/field_presenter.rb', line 87
def repeated?
@field.repeated?
end
|
#required? ⇒ Boolean
91
92
93
|
# File 'lib/gapic/presenters/field_presenter.rb', line 91
def required?
@field.required?
end
|
#type_name ⇒ Object
TODO: remove, only used in tests
66
67
68
|
# File 'lib/gapic/presenters/field_presenter.rb', line 66
def type_name
@field.type_name
end
|
#type_name_full ⇒ Object
70
71
72
73
|
# File 'lib/gapic/presenters/field_presenter.rb', line 70
def type_name_full
return nil if type_name.blank?
ruby_namespace @api, type_name
end
|