class Gapic::Generators::BaseGenerator
The generator orchestrates the rendering of templates.
Public Class Methods
new(api)
click to toggle source
Initializes the generator.
@param api [Gapic::Schema::Api] The API model/context to
generate.
# File lib/gapic/generators/base_generator.rb, line 30 def initialize api @api = api end
Public Instance Methods
generate()
click to toggle source
Generates all the files for the API.
@return [Array<
Google::Protobuf::Compiler::CodeGeneratorResponse::File>] The files that were generated for the API.
# File lib/gapic/generators/base_generator.rb, line 39 def generate raise "must implement" end
Private Instance Methods
controller()
click to toggle source
# File lib/gapic/generators/base_generator.rb, line 58 def controller # Each controller gets a new class, so multiple generators can be # active at the same time without stomping on each other. @controller ||= Class.new(ActionController::Base).new end
format_config()
click to toggle source
# File lib/gapic/generators/base_generator.rb, line 78 def format_config File.expand_path File.join __dir__, "../../../default-rubocop.yml" end
format_files(files)
click to toggle source
# File lib/gapic/generators/base_generator.rb, line 74 def format_files files FileFormatter.new(format_config, files).files end
generate_file(template, filename, **args)
click to toggle source
# File lib/gapic/generators/base_generator.rb, line 64 def generate_file template, filename, **args content = controller.render_to_string( template: template, formats: :text, locals: args ) Google::Protobuf::Compiler::CodeGeneratorResponse::File.new( name: filename, content: content ) end
Also aliased as: g
use_templates!(template_path)
click to toggle source
# File lib/gapic/generators/base_generator.rb, line 45 def use_templates! template_path template_path = File.expand_path template_path helpers_path = File.join template_path, "helpers" # Configure Dependencies to know how to load helpers ActiveSupport::Dependencies.autoload_paths.prepend helpers_path # Configure the controller to know about the templates and helpers controller.prepend_view_path template_path controller.class.helper \ controller.class.all_helpers_from_path helpers_path end