Class: Gapic::Schema::Service

Inherits:
Proto
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/gapic/schema/wrappers.rb

Overview

Wrapper for a protobuf service.

Instance Attribute Summary collapse

Attributes inherited from Proto

#address, #descriptor, #docs, #parent

Instance Method Summary collapse

Methods inherited from Proto

#docs_leading_comments, #leading_comments, #leading_detached_comments, #path, #span, #trailing_comments

Constructor Details

#initialize(descriptor, address, docs, methods) ⇒ Service

Initializes a Service object.

Parameters:



222
223
224
225
226
# File 'lib/gapic/schema/wrappers.rb', line 222

def initialize descriptor, address, docs, methods
  super descriptor, address, docs
  @methods = methods || []
  @methods.each { |m| m.parent = self }
end

Instance Attribute Details

#methods ⇒ Object (readonly)

@ return [Enumerable] The methods of this service.



210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
# File 'lib/gapic/schema/wrappers.rb', line 210

class Service < Proto
  extend Forwardable
  attr_reader :methods

  # Initializes a Service object.
  # @param descriptor [Google::Protobuf::ServiceDescriptorProto] 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 methods [Enumerable<Method>] The methods of this service.
  def initialize descriptor, address, docs, methods
    super descriptor, address, docs
    @methods = methods || []
    @methods.each { |m| m.parent = self }
  end

  # @return [String] The hostname for this service
  #   (e.g. "foo.googleapis.com"). This should be specified with no
  #   prefix.
  def host
    options[:".google.api.default_host"] if options
  end

  # @return [Array<String>] The OAuth scopes information for the client.
  def scopes
    String(options[:".google.api.oauth_scopes"]).split "," if options
  end

  # @return [String] Ruby Package
  def ruby_package
    return nil if parent.nil?

    parent.ruby_package
  end

  # @return [Array<Google::Api::ResourceDescriptor>] A representation of the resource.
  #   This is generally intended to be attached to the "name" field.
  #   See `google/api/resource.proto`.
  def resources
    require "gapic/resource_lookup"

    @resources ||= Gapic::ResourceLookup.for_service self
  end

  # @!method name
  #   @return [String] the unqualified name of the service.
  # @!method options
  #   @return [Google::Protobuf::ServiceOptions] the options of this
  #     service.
  def_delegators(
    :descriptor,
    :name,
    :options
  )
end

Instance Method Details

#host ⇒ String

Returns The hostname for this service (e.g. "foo.googleapis.com"). This should be specified with no prefix.

Returns:

  • (String) —

    The hostname for this service (e.g. "foo.googleapis.com"). This should be specified with no prefix.



231
232
233
# File 'lib/gapic/schema/wrappers.rb', line 231

def host
  options[:".google.api.default_host"] if options
end

#name ⇒ String

Returns the unqualified name of the service.

Returns:

  • (String) —

    the unqualified name of the service.



261
262
263
264
265
# File 'lib/gapic/schema/wrappers.rb', line 261

def_delegators(
  :descriptor,
  :name,
  :options
)

#options ⇒ Google::Protobuf::ServiceOptions

Returns the options of this service.

Returns:



261
262
263
264
265
# File 'lib/gapic/schema/wrappers.rb', line 261

def_delegators(
  :descriptor,
  :name,
  :options
)

#resources ⇒ Array<Google::Api::ResourceDescriptor>

Returns A representation of the resource. This is generally intended to be attached to the "name" field. See google/api/resource.proto.

Returns:

  • (Array<Google::Api::ResourceDescriptor>) —

    A representation of the resource. This is generally intended to be attached to the "name" field. See google/api/resource.proto.



250
251
252
253
254
# File 'lib/gapic/schema/wrappers.rb', line 250

def resources
  require "gapic/resource_lookup"

  @resources ||= Gapic::ResourceLookup.for_service self
end

#ruby_package ⇒ String

Returns Ruby Package.

Returns:

  • (String) —

    Ruby Package



241
242
243
244
245
# File 'lib/gapic/schema/wrappers.rb', line 241

def ruby_package
  return nil if parent.nil?

  parent.ruby_package
end

#scopes ⇒ Array<String>

Returns The OAuth scopes information for the client.

Returns:

  • (Array<String>) —

    The OAuth scopes information for the client.



236
237
238
# File 'lib/gapic/schema/wrappers.rb', line 236

def scopes
  String(options[:".google.api.oauth_scopes"]).split "," if options
end