Class: Gapic::PackageSnippets
- Inherits:
-
Object
- Object
- Gapic::PackageSnippets
- Defined in:
- lib/gapic/package_snippets.rb
Overview
An object that collects snippets for a package and generates the metadata content.
Instance Method Summary collapse
-
#add(method_presenter:, snippet_presenter:, snippet_file:) ⇒ self
Add a snippet to the collection.
-
#files ⇒ Array<Google::Protobuf::Compiler::CodeGeneratorResponse::File>
Return a list of files to render for this package.
-
#initialize(proto_package:, gem_name:, snippet_dir: "snippets") ⇒ PackageSnippets
constructor
Start collecting snippets for a package.
Constructor Details
#initialize(proto_package:, gem_name:, snippet_dir: "snippets") ⇒ PackageSnippets
Start collecting snippets for a package
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/gapic/package_snippets.rb', line 38 def initialize proto_package:, gem_name:, snippet_dir: "snippets" api = SnippetIndex::Api.new( id: proto_package, version: proto_package.split(".").last ) client_library_object = SnippetIndex::ClientLibrary.new( name: gem_name, version: "", language: "RUBY", apis: [api] ) @index_object = SnippetIndex::Index.new( client_library: client_library_object ) @metadata_filename = "#{snippet_dir}/snippet_metadata_#{proto_package}.json" @snippet_files = [] end |
Instance Method Details
#add(method_presenter:, snippet_presenter:, snippet_file:) ⇒ self
Add a snippet to the collection
64 65 66 67 68 69 70 71 |
# File 'lib/gapic/package_snippets.rb', line 64 def add method_presenter:, snippet_presenter:, snippet_file: service_presenter = method_presenter.service snippet_lines = [""] + snippet_file.content.split("\n") @index_object.snippets << build_snippet_object(snippet_presenter, method_presenter, service_presenter, snippet_lines) @snippet_files << snippet_file self end |
#files ⇒ Array<Google::Protobuf::Compiler::CodeGeneratorResponse::File>
Return a list of files to render for this package. This includes all the snippet files themselves, and the metadata file.
79 80 81 82 83 84 85 86 |
# File 'lib/gapic/package_snippets.rb', line 79 def files = JSON.pretty_generate json_value_for @index_object = Google::Protobuf::Compiler::CodeGeneratorResponse::File.new( name: @metadata_filename, content: ) @snippet_files + [] end |