/// <summary> /// Initializes a new instance of the class RubyCodeGenerator. /// </summary> /// <param name="settings">The settings.</param> public RubyCodeGenerator(Settings settings) : base(settings) { CodeNamer = new RubyCodeNamer(); this.packageVersion = Settings.PackageVersion; this.packageName = Settings.PackageName; if (Settings.CustomSettings.ContainsKey("Name")) { this.sdkName = Settings.CustomSettings["Name"].ToString(); } if (sdkName == null) { this.sdkName = Path.GetFileNameWithoutExtension(Settings.Input); } if (sdkName == null) { sdkName = "client"; } this.sdkName = RubyCodeNamer.UnderscoreCase(CodeNamer.RubyRemoveInvalidCharacters(this.sdkName)); this.sdkPath = this.packageName ?? this.sdkName; this.modelsPath = Path.Combine(this.sdkPath, "models"); // AutoRest generated code for Ruby and Azure.Ruby generator will live inside "generated" sub-folder settings.OutputDirectory = Path.Combine(settings.OutputDirectory, GeneratedFolderName); }
/// <summary> /// Generates Ruby code for service client. /// </summary> /// <param name="serviceClient">The service client.</param> /// <returns>Async task for generating SDK files.</returns> public override async Task Generate(ServiceClient serviceClient) { // Service client var serviceClientTemplate = new ServiceClientTemplate { Model = new ServiceClientTemplateModel(serviceClient), }; await Write(serviceClientTemplate, Path.Combine(sdkPath, RubyCodeNamer.UnderscoreCase(serviceClient.Name) + ImplementationFileExtension)); // Method groups foreach (var group in serviceClient.MethodGroups) { var groupTemplate = new MethodGroupTemplate { Model = new MethodGroupTemplateModel(serviceClient, group), }; await Write(groupTemplate, Path.Combine(sdkPath, RubyCodeNamer.UnderscoreCase(group) + ImplementationFileExtension)); } // Models foreach (var model in serviceClient.ModelTypes) { var modelTemplate = new ModelTemplate { Model = new ModelTemplateModel(model, serviceClient.ModelTypes) }; await Write(modelTemplate, Path.Combine(modelsPath, RubyCodeNamer.UnderscoreCase(model.Name) + ImplementationFileExtension)); } // Enums foreach (var enumType in serviceClient.EnumTypes) { var enumTemplate = new EnumTemplate { Model = new EnumTemplateModel(enumType), }; await Write(enumTemplate, Path.Combine(modelsPath, RubyCodeNamer.UnderscoreCase(enumTemplate.Model.TypeDefinitionName) + ImplementationFileExtension)); } // Requirements var requirementsTemplate = new RequirementsTemplate { Model = new RequirementsTemplateModel(serviceClient, this.packageName ?? this.sdkName, this.ImplementationFileExtension, this.Settings.Namespace), }; await Write(requirementsTemplate, RubyCodeNamer.UnderscoreCase(this.packageName ?? this.sdkName) + ImplementationFileExtension); // Version File if (!string.IsNullOrEmpty(this.packageVersion)) { var versionTemplate = new VersionTemplate { Model = new VersionTemplateModel(packageVersion), }; await Write(versionTemplate, Path.Combine(sdkPath, "version" + ImplementationFileExtension)); } // Module Definition File if (!string.IsNullOrEmpty(Settings.Namespace)) { var modTemplate = new ModuleDefinitionTemplate { Model = new ModuleDefinitionTemplateModel(Settings.Namespace), }; await Write(modTemplate, Path.Combine(sdkPath, "module_definition" + ImplementationFileExtension)); } }