class Google::Apis::Generator

Generates ruby classes for APIs from discovery documents @private

@private

@private

@private

Constants

Discovery

#<RDoc::Comment:0x103185ac>


#<RDoc::Comment:0x102b6758>


#<RDoc::Comment:0xf44c7a8>


#<RDoc::Comment:0xe5147f4>

TEMPLATE_DIR

Directory containing ERB templates

Public Class Methods

new(api_names: nil) click to toggle source

Load templates

# File lib/google/apis/generator.rb, line 30
def initialize(api_names: nil)
  @names = Google::Apis::Generator::Names.new(api_names || File.join(Google::Apis::ROOT, 'api_names.yaml'))
  @module_template = Template.load('module.rb')
  @service_template = Template.load('service.rb')
  @classes_template = Template.load('classes.rb')
  @representations_template = Template.load('representations.rb')
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 61
def dump_api_names
  @names.dump
end
parse_description(json) click to toggle source
# File lib/google/apis/generator.rb, line 65
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 44
def render(json)
  api = parse_description(json)
  Annotator.process(api, @names)
  base_path = ActiveSupport::Inflector.underscore(api.qualified_name)
  context = {
    'api' => api
  }
  files = {}
  files[base_path + '.rb'] = @module_template.render(context)
  files[File.join(base_path, 'service.rb')] = @service_template.render(context)
  files[File.join(base_path, 'classes.rb')] = @classes_template.render(context)
  files[File.join(base_path, 'representations.rb')] = @representations_template.render(context)
  files
end