@basketry/sorbet
Advanced tools
Comparing version 0.0.13 to 0.0.14
@@ -6,2 +6,3 @@ "use strict"; | ||
const case_1 = require("case"); | ||
const _1 = require("."); | ||
const name_factory_1 = require("./name-factory"); | ||
@@ -22,3 +23,8 @@ const warning_1 = require("./warning"); | ||
const enumFiles = this.service.enums.map((e) => this.buildEnumFile(e)); | ||
return [...interfaceFiles, ...typeFiles, ...enumFiles]; | ||
return [ | ||
...interfaceFiles, | ||
...typeFiles, | ||
...enumFiles, | ||
this.buildServiceLocatorFile(), | ||
]; | ||
} | ||
@@ -210,2 +216,60 @@ *comment(text) { | ||
} | ||
buildServiceLocatorFile() { | ||
return { | ||
path: (0, _1.buildServiceLocatorFilepath)(this.service, this.options), | ||
contents: from(this.buildServiceLocator()), | ||
}; | ||
} | ||
*buildServiceLocator() { | ||
var _a, _b, _c; | ||
const self = this; | ||
yield (0, warning_1.warning)(this.service, require('../package.json')); | ||
yield ''; | ||
if ((_c = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.sorbet) === null || _b === void 0 ? void 0 : _b.magicComments) === null || _c === void 0 ? void 0 : _c.length) { | ||
for (const magicComment of this.options.sorbet.magicComments) { | ||
yield `# ${magicComment}`; | ||
} | ||
yield ''; | ||
} | ||
yield '# typed: strict'; | ||
yield ''; | ||
const versionedModule = (0, _1.buildServiceLocatorNamespace)(this.service, this.options); | ||
yield* block(`module ${versionedModule}`, function* () { | ||
yield* block(`module ${(0, _1.buildServiceLocatorName)()}`, function* () { | ||
yield `extend T::Sig`; | ||
yield `extend T::Helpers`; | ||
yield ''; | ||
yield `interface!`; | ||
for (const int of self.service.interfaces) { | ||
const interfaceName = (0, name_factory_1.buildInterfaceName)(int); | ||
yield ''; | ||
yield `sig { abstract.returns(${(0, name_factory_1.buildInterfaceNamespace)(self.service, self.options)}::${interfaceName}) }`; | ||
yield `def ${(0, case_1.snake)(interfaceName)}`; | ||
yield 'end'; | ||
} | ||
}); | ||
}); | ||
yield ''; | ||
yield `# The following template can be used to create an implementation of the ${(0, _1.buildServiceLocatorName)()}.`; | ||
yield `# Note that if the original service definition is updated, this template may also be`; | ||
yield `# updated; however, your implementation will remain as-is. In such a case, you will need`; | ||
yield `# to manually update your implementation to match the ${(0, _1.buildServiceLocatorName)()} interface.`; | ||
yield ''; | ||
yield* comment(function* () { | ||
yield* block(`class TemplateServiceLocator`, function* () { | ||
yield `extend T::Sig`; | ||
yield ''; | ||
yield `include ${(0, _1.buildServiceLocatorNamespace)(self.service, self.options)}::${(0, _1.buildServiceLocatorName)()}`; | ||
for (const int of self.service.interfaces) { | ||
const interfaceName = (0, name_factory_1.buildInterfaceName)(int); | ||
yield ''; | ||
yield `sig { override.returns(${(0, name_factory_1.buildInterfaceNamespace)(self.service, self.options)}::${interfaceName}) }`; | ||
yield `def ${(0, case_1.snake)(interfaceName)}`; | ||
yield* indent(`raise NotImplementedError`); | ||
yield 'end'; | ||
} | ||
}); | ||
}); | ||
yield ''; | ||
} | ||
} | ||
@@ -241,2 +305,7 @@ function sortParameters(parameters) { | ||
} | ||
function* comment(lines) { | ||
for (const line of typeof lines === 'function' ? lines() : lines) { | ||
yield line.length ? `# ${line}` : '#'; | ||
} | ||
} | ||
//# sourceMappingURL=interface-factory.js.map |
@@ -17,4 +17,7 @@ import { Enum, Interface, Method, Parameter, Property, Service, Type, TypedValue } from 'basketry'; | ||
export declare function buildEnumFilepath(e: Enum, service: Service, options?: NamespacedSorbetOptions): string[]; | ||
export declare function buildServiceLocatorName(): string; | ||
export declare function buildServiceLocatorNamespace(service: Service, options?: NamespacedSorbetOptions): string; | ||
export declare function buildServiceLocatorFilepath(service: Service, options?: NamespacedSorbetOptions): string[]; | ||
export declare function buildPropertyName(property: Property): string; | ||
export declare function buildParameterName(parameter: Parameter): string; | ||
export declare function buildMethodName(method: Method): string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.buildMethodName = exports.buildParameterName = exports.buildPropertyName = exports.buildEnumFilepath = exports.buildEnumNamespace = exports.buildTypeName = exports.buildTypeFilepath = exports.buildTypeNamespace = exports.buildInterfaceFilepath = exports.buildInterfaceNamespace = exports.buildInterfaceName = exports.buildNamespace = void 0; | ||
exports.buildMethodName = exports.buildParameterName = exports.buildPropertyName = exports.buildServiceLocatorFilepath = exports.buildServiceLocatorNamespace = exports.buildServiceLocatorName = exports.buildEnumFilepath = exports.buildEnumNamespace = exports.buildTypeName = exports.buildTypeFilepath = exports.buildTypeNamespace = exports.buildInterfaceFilepath = exports.buildInterfaceNamespace = exports.buildInterfaceName = exports.buildNamespace = void 0; | ||
const case_1 = require("case"); | ||
@@ -122,2 +122,19 @@ const path_1 = require("path"); | ||
exports.buildEnumFilepath = buildEnumFilepath; | ||
function buildServiceLocatorName() { | ||
return 'ServiceLocator'; | ||
} | ||
exports.buildServiceLocatorName = buildServiceLocatorName; | ||
function buildServiceLocatorNamespace(service, options) { | ||
return buildNamespace('utils', service, options); | ||
} | ||
exports.buildServiceLocatorNamespace = buildServiceLocatorNamespace; | ||
function buildServiceLocatorFilepath(service, options) { | ||
const namespace = buildServiceLocatorNamespace(service, options); | ||
return [ | ||
...subfolder(options), | ||
...namespace.split('::').map(case_1.snake), | ||
`${(0, case_1.snake)(buildServiceLocatorName())}.rb`, | ||
]; | ||
} | ||
exports.buildServiceLocatorFilepath = buildServiceLocatorFilepath; | ||
function buildPropertyName(property) { | ||
@@ -124,0 +141,0 @@ return (0, case_1.snake)(property.name.value); |
{ | ||
"name": "@basketry/sorbet", | ||
"version": "0.0.13", | ||
"version": "0.0.14", | ||
"description": "Basketry generator for generating Sorbet types and interfaces", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
52380
567