Class: Gapic::Presenters::SnippetPresenter::ClientInitializationPresenter

Inherits:
Object
  • Object
show all
Defined in:
lib/gapic/presenters/snippet/client_initialization_presenter.rb

Overview

Presentation information about client object initialization

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(proto, json, phase1:, client_type:) ⇒ ClientInitializationPresenter

Create an client init presenter.

Parameters:

  • proto (Google::Cloud::Tools::SnippetGen::ConfigLanguage::V1::Snippet::ClientInitialization)

    The protobuf representation

  • json (String)

    The JSON representation

  • phase1 (Boolean)

    Whether to inject phase 1 content

  • client_type (String)

    The fully qualified class name of the client



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/gapic/presenters/snippet/client_initialization_presenter.rb', line 35

def initialize proto, json, phase1:, client_type:
  @render_lines = []
  if json&.key? "preClientInitialization"
    proto.pre_client_initialization.each_with_index do |stmt_proto, index|
      statement = StatementPresenter.new stmt_proto, json["preClientInitialization"][index]
      @render_lines += statement.render_lines
    end
  elsif phase1
    @render_lines << "# Create a client object. The client can be reused for multiple calls."
  end
  @render_lines += build_create_code proto, client_type
  @render = @render_lines.join "\n"
end

Instance Attribute Details

#renderString (readonly)

The rendered code as a single string, possibly with line breaks

Returns:

  • (String)


59
60
61
# File 'lib/gapic/presenters/snippet/client_initialization_presenter.rb', line 59

def render
  @render
end

#render_linesArray<String> (readonly)

The lines of rendered code

Returns:

  • (Array<String>)


53
54
55
# File 'lib/gapic/presenters/snippet/client_initialization_presenter.rb', line 53

def render_lines
  @render_lines
end