quicktype-core 7.0.23 → 7.0.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  import { Namer, Name } from "../../Naming";
2
2
  import { ConvenienceRenderer, ForbiddenWordsInfo } from "../../ConvenienceRenderer";
3
3
  import { TargetLanguage } from "../../TargetLanguage";
4
- import { Option, BooleanOption, EnumOption, OptionValues } from "../../RendererOptions";
4
+ import { Option, BooleanOption, EnumOption, OptionValues, StringOption } from "../../RendererOptions";
5
5
  import { Type, ClassType } from "../../Type";
6
6
  import { RenderContext } from "../../Renderer";
7
7
  export declare enum Strictness {
@@ -12,6 +12,7 @@ export declare enum Strictness {
12
12
  export declare const rubyOptions: {
13
13
  justTypes: BooleanOption;
14
14
  strictness: EnumOption<Strictness>;
15
+ namespace: StringOption;
15
16
  };
16
17
  export declare class RubyTargetLanguage extends TargetLanguage {
17
18
  constructor();
@@ -42,6 +43,7 @@ export declare class RubyRenderer extends ConvenienceRenderer {
42
43
  private marshalsImplicitlyToDynamic;
43
44
  private propertyTypeMarshalsImplicitlyFromDynamic;
44
45
  private emitBlock;
46
+ private emitModule;
45
47
  private emitClass;
46
48
  private emitEnum;
47
49
  private emitUnion;
@@ -27,14 +27,15 @@ exports.rubyOptions = {
27
27
  ["strict", Strictness.Strict],
28
28
  ["coercible", Strictness.Coercible],
29
29
  ["none", Strictness.None]
30
- ])
30
+ ]),
31
+ namespace: new RendererOptions_1.StringOption("namespace", "Specify a wrapping Namespace", "NAME", "", "secondary")
31
32
  };
32
33
  class RubyTargetLanguage extends TargetLanguage_1.TargetLanguage {
33
34
  constructor() {
34
35
  super("Ruby", ["ruby"], "rb");
35
36
  }
36
37
  getOptions() {
37
- return [exports.rubyOptions.justTypes, exports.rubyOptions.strictness];
38
+ return [exports.rubyOptions.justTypes, exports.rubyOptions.strictness, exports.rubyOptions.namespace];
38
39
  }
39
40
  get supportsOptionalClassProperties() {
40
41
  return true;
@@ -235,6 +236,25 @@ class RubyRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
235
236
  this.indent(emit);
236
237
  this.emitLine("end");
237
238
  }
239
+ emitModule(emit) {
240
+ const emitModuleInner = (moduleName) => {
241
+ const [firstModule, ...subModules] = moduleName.split("::");
242
+ if (subModules.length > 0) {
243
+ this.emitBlock(["module ", firstModule], () => {
244
+ emitModuleInner(subModules.join("::"));
245
+ });
246
+ }
247
+ else {
248
+ this.emitBlock(["module ", moduleName], emit);
249
+ }
250
+ };
251
+ if (this._options.namespace !== undefined && this._options.namespace !== "") {
252
+ emitModuleInner(this._options.namespace);
253
+ }
254
+ else {
255
+ emit();
256
+ }
257
+ }
238
258
  emitClass(c, className) {
239
259
  this.emitDescription(this.descriptionForType(c));
240
260
  this.emitBlock(["class ", className, " < Dry::Struct"], () => {
@@ -468,36 +488,45 @@ class RubyRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
468
488
  this.emitLine("require 'dry-types'");
469
489
  this.emitLine("require 'dry-struct'");
470
490
  this.ensureBlankLine();
471
- this.emitTypesModule();
472
- this.forEachDeclaration("leading-and-interposing", decl => {
473
- if (decl.kind === "forward") {
474
- this.emitCommentLines(["(forward declaration)"]);
475
- this.emitLine("class ", this.nameForNamedType(decl.type), " < Dry::Struct; end");
476
- }
477
- });
478
- this.forEachNamedType("leading-and-interposing", (c, n) => this.emitClass(c, n), (e, n) => this.emitEnum(e, n), (u, n) => this.emitUnion(u, n));
479
- if (!this._options.justTypes) {
480
- this.forEachTopLevel("leading-and-interposing", (topLevel, name) => {
481
- const self = Source_1.modifySource(Strings_1.snakeCase, name);
482
- // The json gem defines to_json on maps and primitives, so we only need to supply
483
- // it for arrays.
484
- const needsToJsonDefined = "array" === topLevel.kind;
485
- this.emitBlock(["class ", name], () => {
486
- this.emitBlock(["def self.from_json!(json)"], () => {
487
- if (needsToJsonDefined) {
488
- this.emitLine(self, " = ", this.fromDynamic(topLevel, "JSON.parse(json, quirks_mode: true)"));
489
- this.emitBlock([self, ".define_singleton_method(:to_json) do"], () => {
490
- this.emitLine("JSON.generate(", this.toDynamic(topLevel, "self"), ")");
491
+ this.emitModule(() => {
492
+ this.emitTypesModule();
493
+ this.forEachDeclaration("leading-and-interposing", decl => {
494
+ if (decl.kind === "forward") {
495
+ this.emitCommentLines(["(forward declaration)"]);
496
+ this.emitModule(() => {
497
+ this.emitLine("class ", this.nameForNamedType(decl.type), " < Dry::Struct; end");
498
+ });
499
+ }
500
+ });
501
+ this.forEachNamedType("leading-and-interposing", (c, n) => this.emitClass(c, n), (e, n) => this.emitEnum(e, n), (u, n) => this.emitUnion(u, n));
502
+ if (!this._options.justTypes) {
503
+ this.forEachTopLevel("leading-and-interposing", (topLevel, name) => {
504
+ const self = Source_1.modifySource(Strings_1.snakeCase, name);
505
+ // The json gem defines to_json on maps and primitives, so we only need to supply
506
+ // it for arrays.
507
+ const needsToJsonDefined = "array" === topLevel.kind;
508
+ const classDeclaration = () => {
509
+ this.emitBlock(["class ", name], () => {
510
+ this.emitBlock(["def self.from_json!(json)"], () => {
511
+ if (needsToJsonDefined) {
512
+ this.emitLine(self, " = ", this.fromDynamic(topLevel, "JSON.parse(json, quirks_mode: true)"));
513
+ this.emitBlock([self, ".define_singleton_method(:to_json) do"], () => {
514
+ this.emitLine("JSON.generate(", this.toDynamic(topLevel, "self"), ")");
515
+ });
516
+ this.emitLine(self);
517
+ }
518
+ else {
519
+ this.emitLine(this.fromDynamic(topLevel, "JSON.parse(json, quirks_mode: true)"));
520
+ }
491
521
  });
492
- this.emitLine(self);
493
- }
494
- else {
495
- this.emitLine(this.fromDynamic(topLevel, "JSON.parse(json, quirks_mode: true)"));
496
- }
522
+ });
523
+ };
524
+ this.emitModule(() => {
525
+ classDeclaration();
497
526
  });
498
- });
499
- }, t => this.namedTypeToNameForTopLevel(t) === undefined);
500
- }
527
+ }, t => this.namedTypeToNameForTopLevel(t) === undefined);
528
+ }
529
+ });
501
530
  }
502
531
  }
503
532
  exports.RubyRenderer = RubyRenderer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quicktype-core",
3
- "version": "7.0.23",
3
+ "version": "7.0.24",
4
4
  "description": "The quicktype engine as a library",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/index.js",
@@ -45,6 +45,6 @@
45
45
  "fs": false
46
46
  },
47
47
  "config": {
48
- "commit": "740de7cea038033d9d2b00188c685ca3d4802773"
48
+ "commit": "2dc22cb8dee03e613da69ca99ab2b4057f5bf68a"
49
49
  }
50
50
  }