class Gapic::GemBuilder

The builder created files for new extension gems.

Public Class Methods

new(name, path) click to toggle source

Initializes the builder.

@param name [String] The name of the new extension gem. @param path [String] The directory to write the gem files.

# File lib/gapic/gem_builder.rb, line 31
def initialize name, path
  @name = name
  @path = path
end

Public Instance Methods

bootstrap() click to toggle source

Writes all the files for the gem.

# File lib/gapic/gem_builder.rb, line 39
def bootstrap
  gen "readme.erb",     "README.md"
  gen "gemspec.erb",    "gapic-generator-#{gem_name}.gemspec"
  gen "rakefile.erb",   "Rakefile"
  gen "gemfile.erb",    "Gemfile"
  gen "gitignore.erb",  ".gitignore"
  gen "rubocop.erb",    ".rubocop.yml"
  gen "dockerfile.erb", "Dockerfile"
  gen "entrypoint.erb", "docker-entrypoint.sh"
  gen "gapic_sh.erb",   "gapic.sh"
  gen "binary.erb",     "bin/protoc-gen-ruby_#{gem_name}"
  gen "generator.erb",
      "lib/gapic/generators/#{gem_name}_generator.rb"
  gen "version.erb",
      "lib/gapic/generator/#{gem_name}/version.rb"
  gen "test_helper.erb",    "test/test_helper.rb"
  gen "test_generator.erb", "test/generators/#{gem_name}_test.rb"
  cp  "speech_desc.bin",    "proto_input/speech_desc.bin"
end

Private Instance Methods

controller() click to toggle source
# File lib/gapic/gem_builder.rb, line 73
def controller
  @controller ||= Class.new(ActionController::Base).new.tap do |c|
    # Configure the controller to know about the templates
    c.prepend_view_path template_path
  end
end
cp(from, to) click to toggle source
# File lib/gapic/gem_builder.rb, line 80
def cp from, to
  input_path = File.join template_path, from
  target_path = File.join @path, to
  FileUtils.mkdir_p File.dirname(target_path)
  FileUtils.cp input_path, target_path
end
gem_class_prefix() click to toggle source
# File lib/gapic/gem_builder.rb, line 69
def gem_class_prefix
  ActiveSupport::Inflector.camelize @name
end
gem_name() click to toggle source
# File lib/gapic/gem_builder.rb, line 65
def gem_name
  ActiveSupport::Inflector.underscore @name
end
gen(template, filename) click to toggle source
# File lib/gapic/gem_builder.rb, line 87
def gen template, filename
  content = controller.render_to_string(
    template: template,
    formats:  :text,
    locals:   { gem_name: gem_name, gem_class_prefix: gem_class_prefix }
  )
  target_path = File.join @path, filename
  FileUtils.mkdir_p File.dirname(target_path)
  File.write target_path, content
end
template_path() click to toggle source
# File lib/gapic/gem_builder.rb, line 61
def template_path
  File.join __dir__, "../../gem_templates"
end