diff --git a/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/azure_report_spec.rb b/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/azure_report_spec.rb index 6c69f914f76fe..b0f8ec0d72983 100644 --- a/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/azure_report_spec.rb +++ b/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/azure_report_spec.rb @@ -2,7 +2,7 @@ $: << 'RspecTests/Generated/azure_report' -require 'azure_report' +require 'generated/azure_report' include AzureReportModule diff --git a/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/azure_special_properties_spec.rb b/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/azure_special_properties_spec.rb index 6ff29ac477499..45d7abcd09ada 100644 --- a/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/azure_special_properties_spec.rb +++ b/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/azure_special_properties_spec.rb @@ -5,7 +5,7 @@ require 'rspec' require 'securerandom' -require 'azure_special_properties' +require 'generated/azure_special_properties' include AzureSpecialPropertiesModule diff --git a/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/azure_url_spec.rb b/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/azure_url_spec.rb index ef1b8322f3a1c..7124691360b02 100644 --- a/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/azure_url_spec.rb +++ b/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/azure_url_spec.rb @@ -5,7 +5,7 @@ require 'rspec' require 'securerandom' -require 'subscription_id_api_version' +require 'generated/subscription_id_api_version' include AzureUrlModule diff --git a/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/custom_base_uri_more_spec.rb b/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/custom_base_uri_more_spec.rb index 29a5dff237a7f..e1ef43d73651b 100644 --- a/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/custom_base_uri_more_spec.rb +++ b/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/custom_base_uri_more_spec.rb @@ -2,7 +2,7 @@ $: << 'RspecTests/Generated/custom_base_uri_more' -require 'custom_base_url_more_options' +require 'generated/custom_base_url_more_options' require 'uri' module CustomBaseUriMoreModule diff --git a/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/custom_base_uri_spec.rb b/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/custom_base_uri_spec.rb index c3eb81c719d54..87896e1279073 100644 --- a/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/custom_base_uri_spec.rb +++ b/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/custom_base_uri_spec.rb @@ -2,7 +2,7 @@ $: << 'RspecTests/Generated/custom_base_uri' -require 'custom_base_url' +require 'generated/custom_base_url' require 'uri' module CustomBaseUriModule diff --git a/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/head_exception_spec.rb b/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/head_exception_spec.rb index b7ac162949eb7..4117dde4422eb 100644 --- a/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/head_exception_spec.rb +++ b/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/head_exception_spec.rb @@ -3,7 +3,7 @@ $: << 'RspecTests/Generated/head_exceptions' require 'rspec' -require 'head_exceptions' +require 'generated/head_exceptions' include HeadExceptionsModule diff --git a/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/head_spec.rb b/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/head_spec.rb index 7b4cd203fb352..6be813c0508fd 100644 --- a/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/head_spec.rb +++ b/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/head_spec.rb @@ -3,7 +3,7 @@ $: << 'RspecTests/Generated/head' require 'rspec' -require 'head' +require 'generated/head' include HeadModule diff --git a/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/lro_spec.rb b/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/lro_spec.rb index 02895779f1426..d5701bc983b8d 100644 --- a/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/lro_spec.rb +++ b/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/lro_spec.rb @@ -3,7 +3,7 @@ $: << 'RspecTests/Generated/lro' require 'rspec' -require 'lro' +require 'generated/lro' include LroModule include LroModule::Models diff --git a/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/paging_spec.rb b/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/paging_spec.rb index a6e6ea41726bf..e78f08e8c5338 100644 --- a/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/paging_spec.rb +++ b/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/paging_spec.rb @@ -3,7 +3,7 @@ $: << 'RspecTests/Generated/paging' require 'rspec' -require 'paging' +require 'generated/paging' include PagingModule diff --git a/AutoRest/Generators/Ruby/Azure.Ruby/AzureRubyCodeGenerator.cs b/AutoRest/Generators/Ruby/Azure.Ruby/AzureRubyCodeGenerator.cs index d3aa58bea0991..b70c7463d5e3b 100644 --- a/AutoRest/Generators/Ruby/Azure.Ruby/AzureRubyCodeGenerator.cs +++ b/AutoRest/Generators/Ruby/Azure.Ruby/AzureRubyCodeGenerator.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. +using System; using System.IO; using System.Linq; using System.Threading.Tasks; @@ -108,13 +109,13 @@ public override async Task Generate(ServiceClient serviceClient) // Models foreach (var model in serviceClient.ModelTypes) { - if ((model.Extensions.ContainsKey(AzureExtensions.ExternalExtension) && - (bool) model.Extensions[AzureExtensions.ExternalExtension]) + if ((model.Extensions.ContainsKey(AzureExtensions.ExternalExtension) && + (bool)model.Extensions[AzureExtensions.ExternalExtension]) || model.Name == "Resource" || model.Name == "SubResource") { continue; } - + var modelTemplate = new ModelTemplate { Model = new AzureModelTemplateModel(model, serviceClient.ModelTypes), @@ -136,28 +137,28 @@ public override async Task Generate(ServiceClient serviceClient) // Requirements var requirementsTemplate = new RequirementsTemplate { - Model = new AzureRequirementsTemplateModel(serviceClient, this.packageName ?? this.sdkName, this.ImplementationFileExtension, this.Settings.Namespace), + Model = new AzureRequirementsTemplateModel(serviceClient, this.packageName ?? this.sdkName, this.ImplementationFileExtension, this.Settings.Namespace, this.packageVersion), }; await Write(requirementsTemplate, RubyCodeNamer.UnderscoreCase(this.packageName ?? this.sdkName) + ImplementationFileExtension); - - // Version File - if(this.packageVersion != null) + + // Version File + if (this.packageVersion != null) { var versionTemplate = new VersionTemplate { Model = new VersionTemplateModel(packageVersion), }; - await Write(versionTemplate, Path.Combine(sdkPath, "version" + ImplementationFileExtension)); + await Write(versionTemplate, Path.Combine(sdkPath, "version" + ImplementationFileExtension)); } - + // Module Definition File - if(Settings.Namespace != null) + if (Settings.Namespace != null) { var modTemplate = new ModuleDefinitionTemplate { Model = new ModuleDefinitionTemplateModel(Settings.Namespace), }; - await Write(modTemplate, Path.Combine(sdkPath, "module_definition" + ImplementationFileExtension)); + await Write(modTemplate, Path.Combine(sdkPath, "module_definition" + ImplementationFileExtension)); } } } diff --git a/AutoRest/Generators/Ruby/Azure.Ruby/TemplateModels/AzureRequirementsTemplateModel.cs b/AutoRest/Generators/Ruby/Azure.Ruby/TemplateModels/AzureRequirementsTemplateModel.cs index 345d6e2f7e19a..cf80bebf54c00 100644 --- a/AutoRest/Generators/Ruby/Azure.Ruby/TemplateModels/AzureRequirementsTemplateModel.cs +++ b/AutoRest/Generators/Ruby/Azure.Ruby/TemplateModels/AzureRequirementsTemplateModel.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. See License.txt in the project root for license information. using System; +using System.Globalization; using Microsoft.Rest.Generator.ClientModel; using Microsoft.Rest.Generator.Ruby; @@ -31,8 +32,9 @@ protected override bool ExcludeModel(CompositeType model) /// The name of the generated SDK, required for proper folder structuring. /// The files extension. /// The namespace of the SDK. - public AzureRequirementsTemplateModel(ServiceClient serviceClient, string sdkName, string filesExtension, string ns) - : base(serviceClient, sdkName, filesExtension, ns) + /// The name of the package version to be used in creating a version.rb file. + public AzureRequirementsTemplateModel(ServiceClient serviceClient, string sdkName, string filesExtension, string ns, string packageVersion) + : base(serviceClient, sdkName, filesExtension, ns, packageVersion) { } diff --git a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/array_spec.rb b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/array_spec.rb index d85c50307e6ac..c78494c9ec7e3 100644 --- a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/array_spec.rb +++ b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/array_spec.rb @@ -4,7 +4,7 @@ $: << 'RspecTests/Generated/array' require 'rspec' -require 'body_array' +require 'generated/body_array' require 'helper' module ArrayModule diff --git a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/bool_spec.rb b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/bool_spec.rb index 3f1948f8a6641..e1e20b9e28c52 100644 --- a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/bool_spec.rb +++ b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/bool_spec.rb @@ -3,7 +3,7 @@ $: << 'RspecTests' $: << 'RspecTests/Generated/boolean' -require 'body_boolean' +require 'generated/body_boolean' module BooleanModule diff --git a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/byte_spec.rb b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/byte_spec.rb index a7a1f9f7a0bb0..a0d24f67a003c 100644 --- a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/byte_spec.rb +++ b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/byte_spec.rb @@ -2,7 +2,7 @@ $: << 'RspecTests/Generated/byte' -require 'body_byte' +require 'generated/body_byte' module ByteModule diff --git a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/complex_spec.rb b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/complex_spec.rb index bf9ba30c52d8a..2274cc9edeaae 100644 --- a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/complex_spec.rb +++ b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/complex_spec.rb @@ -3,7 +3,7 @@ $: << 'RspecTests/Generated/complex' require 'base64' -require 'body_complex' +require 'generated/body_complex' module ComplexModule include ComplexModule::Models diff --git a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/date_spec.rb b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/date_spec.rb index 616f1289f90b3..a14a620916618 100644 --- a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/date_spec.rb +++ b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/date_spec.rb @@ -3,7 +3,7 @@ $: << 'RspecTests/Generated/date' require 'rspec' -require 'body_date' +require 'generated/body_date' describe DateModule::Date do diff --git a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/datetime_rfc1123_spec.rb b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/datetime_rfc1123_spec.rb index 1ba32b69debcf..883ed2f31162c 100644 --- a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/datetime_rfc1123_spec.rb +++ b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/datetime_rfc1123_spec.rb @@ -3,7 +3,7 @@ $: << 'RspecTests/Generated/datetime_rfc1123' require 'rspec' -require 'body_datetime_rfc1123' +require 'generated/body_datetime_rfc1123' require_relative './helper' include DatetimeRfc1123Module diff --git a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/datetime_spec.rb b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/datetime_spec.rb index 42e20c9a818b8..2f77591d43b35 100644 --- a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/datetime_spec.rb +++ b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/datetime_spec.rb @@ -3,7 +3,7 @@ $: << 'RspecTests/Generated/datetime' require 'rspec' -require 'body_datetime' +require 'generated/body_datetime' require_relative './helper' include DatetimeModule diff --git a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/dictionary_spec.rb b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/dictionary_spec.rb index 592efbc78dc1b..ed86695c6429c 100644 --- a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/dictionary_spec.rb +++ b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/dictionary_spec.rb @@ -4,7 +4,7 @@ $: << 'RspecTests' require 'base64' -require 'body_dictionary' +require 'generated/body_dictionary' require 'helper' include DictionaryModule diff --git a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/header_spec.rb b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/header_spec.rb index 6378ca13c6ed6..91e2bcbced96d 100644 --- a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/header_spec.rb +++ b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/header_spec.rb @@ -5,7 +5,7 @@ require "base64" -require 'header' +require 'generated/header' module HeaderModule include HeaderModule::Models diff --git a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/http_infrastructure_spec.rb b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/http_infrastructure_spec.rb index e14e17d324a7b..211f3cada7d1a 100644 --- a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/http_infrastructure_spec.rb +++ b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/http_infrastructure_spec.rb @@ -4,7 +4,7 @@ $: << 'RspecTests' require 'rspec' -require 'http_infrastructure.rb' +require 'generated/http_infrastructure.rb' require 'helper' module HttpInfrastructureModule diff --git a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/integer_spec.rb b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/integer_spec.rb index f7556f6741a20..b8a55ad54fa7e 100644 --- a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/integer_spec.rb +++ b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/integer_spec.rb @@ -2,7 +2,7 @@ $: << 'RspecTests/Generated/integer' -require 'body_integer' +require 'generated/body_integer' include IntegerModule diff --git a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/model_flattening_spec.rb b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/model_flattening_spec.rb index 4f78dae9e2244..679ff5e33af9c 100644 --- a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/model_flattening_spec.rb +++ b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/model_flattening_spec.rb @@ -3,7 +3,7 @@ $: << 'RspecTests/Generated/model_flattening' require 'securerandom' -require 'model_flattening' +require 'generated/model_flattening' include ModelFlatteningModule include ModelFlatteningModule::Models diff --git a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/number_spec.rb b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/number_spec.rb index 2d3ee83e457a2..2027da0ee5c53 100644 --- a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/number_spec.rb +++ b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/number_spec.rb @@ -2,7 +2,7 @@ $: << 'RspecTests/Generated/number' -require 'body_number' +require 'generated/body_number' include NumberModule diff --git a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/parameter_grouping_spec.rb b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/parameter_grouping_spec.rb index a17beabd53032..3ac8dbf28c077 100644 --- a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/parameter_grouping_spec.rb +++ b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/parameter_grouping_spec.rb @@ -3,7 +3,7 @@ $: << 'RspecTests/Generated/parameter_grouping' require 'rspec' -require 'azure_parameter_grouping' +require 'generated/azure_parameter_grouping' include ParameterGroupingModule include ParameterGroupingModule::Models diff --git a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/path_items_spec.rb b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/path_items_spec.rb index 680aff9ccb5d7..6c4411c512306 100644 --- a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/path_items_spec.rb +++ b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/path_items_spec.rb @@ -2,7 +2,7 @@ $: << 'RspecTests/Generated/url_items' -require 'url' +require 'generated/url' include UrlModule diff --git a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/path_spec.rb b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/path_spec.rb index 3c2676513fc9f..3dfcf908e9605 100644 --- a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/path_spec.rb +++ b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/path_spec.rb @@ -2,7 +2,7 @@ $: << 'RspecTests/url' -require 'url' +require 'generated/url' include UrlModule diff --git a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/query_spec.rb b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/query_spec.rb index 0fac09f395dc1..2e1e206340953 100644 --- a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/query_spec.rb +++ b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/query_spec.rb @@ -3,7 +3,7 @@ $: << 'RspecTests/url_query' require 'rspec' -require 'url' +require 'generated/url' include UrlModule diff --git a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/report_spec.rb b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/report_spec.rb index 1fe06709bc53d..72c5b92f9d11b 100644 --- a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/report_spec.rb +++ b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/report_spec.rb @@ -2,7 +2,7 @@ $: << 'RspecTests/Generated/report' -require 'report' +require 'generated/report' include ReportModule diff --git a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/required_optional_spec.rb b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/required_optional_spec.rb index fbcc0ecaf6941..531dd672b534b 100644 --- a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/required_optional_spec.rb +++ b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/required_optional_spec.rb @@ -2,7 +2,7 @@ $: << 'RspecTests/Generated/required_optional' -require 'required_optional' +require 'generated/required_optional' include RequiredOptionalModule include RequiredOptionalModule::Models diff --git a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/string_spec.rb b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/string_spec.rb index 223d1cfdb6c1e..3ee8fa777d434 100644 --- a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/string_spec.rb +++ b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/string_spec.rb @@ -2,7 +2,7 @@ $: << 'RspecTests/Generated/string' -require 'body_string' +require 'generated/body_string' include StringModule diff --git a/AutoRest/Generators/Ruby/Ruby/RubyCodeGenerator.cs b/AutoRest/Generators/Ruby/Ruby/RubyCodeGenerator.cs index e111d37612e4a..3e3a7fdc8c720 100644 --- a/AutoRest/Generators/Ruby/Ruby/RubyCodeGenerator.cs +++ b/AutoRest/Generators/Ruby/Ruby/RubyCodeGenerator.cs @@ -13,6 +13,11 @@ namespace Microsoft.Rest.Generator.Ruby /// public class RubyCodeGenerator : CodeGenerator { + /// + /// Name of the generated sub-folder inside ourput directory. + /// + private const string GeneratedFolderName = "generated"; + /// /// The name of the SDK. Determined in the following way: /// if the parameter 'Name' is provided that it becomes the @@ -25,7 +30,7 @@ public class RubyCodeGenerator : CodeGenerator /// The name of the package version to be used in creating a version.rb file /// protected readonly string packageVersion; - + /// /// The name of the package name to be used in creating a version.rb file /// @@ -74,6 +79,9 @@ public RubyCodeGenerator(Settings settings) : base(settings) 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); } /// @@ -190,28 +198,28 @@ public override async Task Generate(ServiceClient serviceClient) // Requirements var requirementsTemplate = new RequirementsTemplate { - Model = new RequirementsTemplateModel(serviceClient, this.packageName ?? this.sdkName, this.ImplementationFileExtension, this.Settings.Namespace), + Model = new RequirementsTemplateModel(serviceClient, this.packageName ?? this.sdkName, this.ImplementationFileExtension, this.Settings.Namespace, this.packageVersion), }; await Write(requirementsTemplate, RubyCodeNamer.UnderscoreCase(this.packageName ?? this.sdkName) + ImplementationFileExtension); - + // Version File - if(!string.IsNullOrEmpty(this.packageVersion)) + if (!string.IsNullOrEmpty(this.packageVersion)) { var versionTemplate = new VersionTemplate { Model = new VersionTemplateModel(packageVersion), }; - await Write(versionTemplate, Path.Combine(sdkPath, "version" + ImplementationFileExtension)); + await Write(versionTemplate, Path.Combine(sdkPath, "version" + ImplementationFileExtension)); } - + // Module Definition File - if(!string.IsNullOrEmpty(Settings.Namespace)) + if (!string.IsNullOrEmpty(Settings.Namespace)) { var modTemplate = new ModuleDefinitionTemplate { Model = new ModuleDefinitionTemplateModel(Settings.Namespace), }; - await Write(modTemplate, Path.Combine(sdkPath, "module_definition" + ImplementationFileExtension)); + await Write(modTemplate, Path.Combine(sdkPath, "module_definition" + ImplementationFileExtension)); } } } diff --git a/AutoRest/Generators/Ruby/Ruby/TemplateModels/RequirementsTemplateModel.cs b/AutoRest/Generators/Ruby/Ruby/TemplateModels/RequirementsTemplateModel.cs index 6fbcf8e55a1be..d38a1b73b7c8e 100644 --- a/AutoRest/Generators/Ruby/Ruby/TemplateModels/RequirementsTemplateModel.cs +++ b/AutoRest/Generators/Ruby/Ruby/TemplateModels/RequirementsTemplateModel.cs @@ -16,6 +16,16 @@ namespace Microsoft.Rest.Generator.Ruby /// public class RequirementsTemplateModel : ServiceClient { + /// + /// Name of the generated sub-folder inside ourput directory. + /// + private const string GeneratedFolderName = "generated"; + + /// + /// Format for the autoload module. + /// + private const string AutoloadFormat = "autoload :{0},{1}'" + GeneratedFolderName + "/{2}/{3}'"; + /// /// Number of spaces between class name and file name required for better readability. /// @@ -30,12 +40,16 @@ public class RequirementsTemplateModel : ServiceClient /// Files extensions. /// private readonly string implementationFileExtension; - + /// /// Namspace of the service client. /// private readonly string ns; + /// + /// The name of the package version to be used in creating a version.rb file. + /// + private readonly string packageVersion; /// /// Returns the ordered list of models. Ordered means that if some model has @@ -87,7 +101,7 @@ private string GetAutoloadFormat(string typeName, string fileName) spacing = sb.ToString(); } - return string.Format("autoload :{0},{1}'{2}/{3}'", typeName, spacing, this.sdkName, fileName); + return string.Format(AutoloadFormat, typeName, spacing, this.sdkName, fileName); } /// @@ -107,10 +121,12 @@ protected virtual bool ExcludeModel(CompositeType model) /// The name of the SDK. /// The files extension. /// The namespace of the SDK. - public RequirementsTemplateModel(ServiceClient serviceClient, string sdkName, string implementationFileExtension, string ns) + /// The name of the package version to be used in creating a version.rb file. + public RequirementsTemplateModel(ServiceClient serviceClient, string sdkName, string implementationFileExtension, string ns, string packageVersion) { this.LoadFrom(serviceClient); this.ns = ns; + this.packageVersion = packageVersion; this.sdkName = sdkName; this.implementationFileExtension = implementationFileExtension; } @@ -174,16 +190,22 @@ public virtual string GetDependencyGems() require 'faraday-cookie_jar' require 'concurrent' require 'ms_rest'"; - if(!string.IsNullOrEmpty(this.ns)) + + if(!string.IsNullOrWhiteSpace(this.ns)) { - return requirements + requirements = requirements + Environment.NewLine - + string.Format(CultureInfo.InvariantCulture, "require '{0}/module_definition'", this.sdkName); + + string.Format(CultureInfo.InvariantCulture, "require '{0}/{1}/module_definition'", GeneratedFolderName, this.sdkName); } - else + + if (!string.IsNullOrWhiteSpace(this.packageVersion)) { - return requirements; + requirements = requirements + + Environment.NewLine + + string.Format(CultureInfo.InvariantCulture, "require '{0}/{1}/version'", GeneratedFolderName, this.sdkName); } + + return requirements; } } }