Class: Gapic::Schema::File

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

Overview

Wrapper for a protobuf file.

Instance Attribute Summary collapse

Attributes inherited from Proto

#address, #descriptor, #docs, #parent

Instance Method Summary collapse

Methods inherited from Proto

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

Constructor Details

#initialize(descriptor, address, docs, messages, enums, services, generate, registry) ⇒ File

Initializes a message object.

Parameters:

  • descriptor (Google::Protobuf::DescriptorProto) —

    the protobuf representation of this service.

  • address (Enumerable<String>) —

    The address of the proto. See

    address for more info.

  • docs (Google::Protobuf::SourceCodeInfo::Location) —

    The docs of the proto. See #docs for more info.

  • messages (Enumerable<Message>) —

    The top level messages of this file.

  • enums (Enumerable<Enum>) —

    The top level enums of this file.

  • services (Enumerable<Service>) —

    The services of this file.

  • generate (Boolean) —

    Whether this file should be generated.



383
384
385
386
387
388
389
390
391
392
393
394
395
396
# File 'lib/gapic/schema/wrappers.rb', line 383

def initialize descriptor, address, docs, messages, enums, services,
               generate, registry
  super descriptor, address, docs
  @messages = messages || []
  @enums = enums || []
  @services = services || []
  @generate = generate
  @registry = registry

  # Apply parent
  @messages.each { |m| m.parent = self }
  @enums.each    { |m| m.parent = self }
  @services.each { |m| m.parent = self }
end

Instance Attribute Details

#enums ⇒ Object (readonly)

@ return [Enumerable] The top level enums contained in this file.



367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
# File 'lib/gapic/schema/wrappers.rb', line 367

class File < Proto
  extend Forwardable
  attr_reader :messages, :enums, :services, :registry

  # Initializes a message object.
  # @param descriptor [Google::Protobuf::DescriptorProto] 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 messages [Enumerable<Message>] The top level messages of this
  #   file.
  # @param enums [Enumerable<Enum>] The top level enums of this file.
  # @param services [Enumerable<Service>] The services of this file.
  # @param generate [Boolean] Whether this file should be generated.
  def initialize descriptor, address, docs, messages, enums, services,
                 generate, registry
    super descriptor, address, docs
    @messages = messages || []
    @enums = enums || []
    @services = services || []
    @generate = generate
    @registry = registry

    # Apply parent
    @messages.each { |m| m.parent = self }
    @enums.each    { |m| m.parent = self }
    @services.each { |m| m.parent = self }
  end

  def containing_file
    self
  end

  def lookup address
    address = address.split(".").reject(&:empty?).join(".")
    @registry[address]
  end

  def generate?
    @generate
  end

  # @return [String] Ruby Package
  def ruby_package
    options[:ruby_package] if options
  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
    options[:".google.api.resource_definition"] if options
  end

  # @!method name
  #   @return [String] file name, relative to root of source tree.
  # @!method package
  #   @return [String] package of the file. e.g. "foo", "foo.bar", etc.
  # @!method dependency
  #   @return [Array<String>] Names of files imported by this file.
  # @!method public_dependency
  #   @return [Array<Integer>] Indexes of the public imported files in the
  #     dependency list returned by #dependency.
  # @!method options
  #   @return [Google::Protobuf::FileOptions] the options of this file.
  def_delegators(
    :descriptor,
    :name,
    :package,
    :dependency,
    :public_dependency,
    :options
  )
end

#messages ⇒ Object (readonly)

@ return [Enumerable] The top level messages contained in this file.



367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
# File 'lib/gapic/schema/wrappers.rb', line 367

class File < Proto
  extend Forwardable
  attr_reader :messages, :enums, :services, :registry

  # Initializes a message object.
  # @param descriptor [Google::Protobuf::DescriptorProto] 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 messages [Enumerable<Message>] The top level messages of this
  #   file.
  # @param enums [Enumerable<Enum>] The top level enums of this file.
  # @param services [Enumerable<Service>] The services of this file.
  # @param generate [Boolean] Whether this file should be generated.
  def initialize descriptor, address, docs, messages, enums, services,
                 generate, registry
    super descriptor, address, docs
    @messages = messages || []
    @enums = enums || []
    @services = services || []
    @generate = generate
    @registry = registry

    # Apply parent
    @messages.each { |m| m.parent = self }
    @enums.each    { |m| m.parent = self }
    @services.each { |m| m.parent = self }
  end

  def containing_file
    self
  end

  def lookup address
    address = address.split(".").reject(&:empty?).join(".")
    @registry[address]
  end

  def generate?
    @generate
  end

  # @return [String] Ruby Package
  def ruby_package
    options[:ruby_package] if options
  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
    options[:".google.api.resource_definition"] if options
  end

  # @!method name
  #   @return [String] file name, relative to root of source tree.
  # @!method package
  #   @return [String] package of the file. e.g. "foo", "foo.bar", etc.
  # @!method dependency
  #   @return [Array<String>] Names of files imported by this file.
  # @!method public_dependency
  #   @return [Array<Integer>] Indexes of the public imported files in the
  #     dependency list returned by #dependency.
  # @!method options
  #   @return [Google::Protobuf::FileOptions] the options of this file.
  def_delegators(
    :descriptor,
    :name,
    :package,
    :dependency,
    :public_dependency,
    :options
  )
end

#registry ⇒ Object (readonly)

Returns the value of attribute registry.



369
370
371
# File 'lib/gapic/schema/wrappers.rb', line 369

def registry
  @registry
end

#services ⇒ Object (readonly)

@ return [Enumerable] The services contained in this file.



367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
# File 'lib/gapic/schema/wrappers.rb', line 367

class File < Proto
  extend Forwardable
  attr_reader :messages, :enums, :services, :registry

  # Initializes a message object.
  # @param descriptor [Google::Protobuf::DescriptorProto] 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 messages [Enumerable<Message>] The top level messages of this
  #   file.
  # @param enums [Enumerable<Enum>] The top level enums of this file.
  # @param services [Enumerable<Service>] The services of this file.
  # @param generate [Boolean] Whether this file should be generated.
  def initialize descriptor, address, docs, messages, enums, services,
                 generate, registry
    super descriptor, address, docs
    @messages = messages || []
    @enums = enums || []
    @services = services || []
    @generate = generate
    @registry = registry

    # Apply parent
    @messages.each { |m| m.parent = self }
    @enums.each    { |m| m.parent = self }
    @services.each { |m| m.parent = self }
  end

  def containing_file
    self
  end

  def lookup address
    address = address.split(".").reject(&:empty?).join(".")
    @registry[address]
  end

  def generate?
    @generate
  end

  # @return [String] Ruby Package
  def ruby_package
    options[:ruby_package] if options
  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
    options[:".google.api.resource_definition"] if options
  end

  # @!method name
  #   @return [String] file name, relative to root of source tree.
  # @!method package
  #   @return [String] package of the file. e.g. "foo", "foo.bar", etc.
  # @!method dependency
  #   @return [Array<String>] Names of files imported by this file.
  # @!method public_dependency
  #   @return [Array<Integer>] Indexes of the public imported files in the
  #     dependency list returned by #dependency.
  # @!method options
  #   @return [Google::Protobuf::FileOptions] the options of this file.
  def_delegators(
    :descriptor,
    :name,
    :package,
    :dependency,
    :public_dependency,
    :options
  )
end

Instance Method Details

#containing_file ⇒ Object



398
399
400
# File 'lib/gapic/schema/wrappers.rb', line 398

def containing_file
  self
end

#dependency ⇒ Array<String>

Returns Names of files imported by this file.

Returns:

  • (Array<String>) —

    Names of files imported by this file.



434
435
436
437
438
439
440
441
# File 'lib/gapic/schema/wrappers.rb', line 434

def_delegators(
  :descriptor,
  :name,
  :package,
  :dependency,
  :public_dependency,
  :options
)

#generate? ⇒ Boolean

Returns:

  • (Boolean)


407
408
409
# File 'lib/gapic/schema/wrappers.rb', line 407

def generate?
  @generate
end

#lookup(address) ⇒ Object



402
403
404
405
# File 'lib/gapic/schema/wrappers.rb', line 402

def lookup address
  address = address.split(".").reject(&:empty?).join(".")
  @registry[address]
end

#name ⇒ String

Returns file name, relative to root of source tree.

Returns:

  • (String) —

    file name, relative to root of source tree.



434
435
436
437
438
439
440
441
# File 'lib/gapic/schema/wrappers.rb', line 434

def_delegators(
  :descriptor,
  :name,
  :package,
  :dependency,
  :public_dependency,
  :options
)

#options ⇒ Google::Protobuf::FileOptions

Returns the options of this file.

Returns:



434
435
436
437
438
439
440
441
# File 'lib/gapic/schema/wrappers.rb', line 434

def_delegators(
  :descriptor,
  :name,
  :package,
  :dependency,
  :public_dependency,
  :options
)

#package ⇒ String

Returns package of the file. e.g. "foo", "foo.bar", etc.

Returns:

  • (String) —

    package of the file. e.g. "foo", "foo.bar", etc.



434
435
436
437
438
439
440
441
# File 'lib/gapic/schema/wrappers.rb', line 434

def_delegators(
  :descriptor,
  :name,
  :package,
  :dependency,
  :public_dependency,
  :options
)

#public_dependency ⇒ Array<Integer>

Returns Indexes of the public imported files in the dependency list returned by #dependency.

Returns:

  • (Array<Integer>) —

    Indexes of the public imported files in the dependency list returned by #dependency.



434
435
436
437
438
439
440
441
# File 'lib/gapic/schema/wrappers.rb', line 434

def_delegators(
  :descriptor,
  :name,
  :package,
  :dependency,
  :public_dependency,
  :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.



419
420
421
# File 'lib/gapic/schema/wrappers.rb', line 419

def resources
  options[:".google.api.resource_definition"] if options
end

#ruby_package ⇒ String

Returns Ruby Package.

Returns:

  • (String) —

    Ruby Package



412
413
414
# File 'lib/gapic/schema/wrappers.rb', line 412

def ruby_package
  options[:ruby_package] if options
end