class Google::Apis::Generator
Generates ruby classes for APIs from discovery documents @private
@private
@private
@private
Constants
- Discovery
- Result
- TEMPLATE_DIR
Directory containing ERB templates
- VERSION
Public Class Methods
new(api_names: nil, api_names_out: nil)
click to toggle source
Load templates
# File lib/google/apis/generator.rb, line 36 def initialize(api_names: nil, api_names_out: nil) @names = Google::Apis::Generator::Names.new(api_names_out || File.join(Google::Apis::ROOT, "api_names_out.yaml"), api_names || File.join(Google::Apis::ROOT, "api_names.yaml")) @templates = {} end
Public Instance Methods
dump_api_names()
click to toggle source
Dump mapping of API names @return [String] Mapping of paths to ruby names in YAML format
# File lib/google/apis/generator.rb, line 91 def dump_api_names @names.dump end
parse_description(json)
click to toggle source
# File lib/google/apis/generator.rb, line 95 def parse_description(json) Discovery::RestDescription::Representation.new(Discovery::RestDescription.new).from_json(json) end
render(json)
click to toggle source
Generates ruby source for an API
@param [String] json
API Description, as JSON text
@return [Hash<String,String>]
Hash of generated files keyed by path
# File lib/google/apis/generator.rb, line 48 def render(json) api = parse_description(json) Annotator.process(api, @names) context = { "api" => api, "generator_version" => Google::Apis::Generator::VERSION } base_path = api.gem_name lib_path = File.join(base_path, "lib") spec_path = File.join(base_path, "spec") module_path = File.join(lib_path, ActiveSupport::Inflector.underscore(api.qualified_name)) result = Result.new({}, File.join(module_path, "gem_version.rb"), File.join(base_path, "CHANGELOG.md"), api.gem_name, api.revision) result.files[File.join(base_path, ".rspec")] = render_template("dot-rspec", context) result.files[File.join(base_path, ".yardopts")] = render_template("dot-yardopts", context) result.files[result.changelog_path] = render_template("initial-changelog.md", context) result.files[File.join(base_path, "Gemfile")] = render_template("gemfile", context) result.files[File.join(base_path, "#{api.gem_name}.gemspec")] = render_template("gemspec", context) result.files[File.join(base_path, "LICENSE.md")] = render_template("license.md", context) result.files[File.join(base_path, "OVERVIEW.md")] = render_template("overview.md", context) result.files[File.join(base_path, "Rakefile")] = render_template("rakefile", context) result.files[File.join(lib_path, "#{api.gem_name}.rb")] = render_template("entry-point.rb", context) result.files[module_path + ".rb"] = render_template("module.rb", context) result.files[File.join(module_path, "classes.rb")] = render_template("classes.rb", context) result.files[File.join(module_path, "representations.rb")] = render_template("representations.rb", context) result.files[File.join(module_path, "service.rb")] = render_template("service.rb", context) result.files[result.version_path] = render_template("initial-gem_version.rb", context) result.files[File.join(spec_path, "generated_spec.rb")] = render_template("generated_spec.rb", context) result.files[File.join(base_path, ".repo-metadata.json")] = render_template("repo-metadata.json", context) result end
render_template(name, context)
click to toggle source
# File lib/google/apis/generator.rb, line 85 def render_template(name, context) (@templates[name] ||= Template.load(name)).render(context) end