combineObject()

in src/langs/swift/combinator.js [98:147]


  combineObject(objects, object_type) {
    let models = objects.filter(obj => obj.type === object_type);
    if (!models.length) {
      return;
    }
    const outputPars = { head: '', body: '', foot: '' };

    /***************************** body ******************************/
    this.level = 0;
    let emitter = new Emitter(this.config);
    models.forEach((object, index) => {
      this.properties = {};
      object.body.filter(node => is.prop(node)).forEach(node => {
        this.properties[node.name] = node;
      });
      this.emitClass(emitter, object, object.subObject);
      if (index !== models.length - 1) {
        emitter.emitln();
      }
    });
    outputPars.body = emitter.output;

    /***************************** head ******************************/
    emitter = new Emitter(this.config);
    if (this.config.exec) {
      emitter.emitln('#!/usr/bin/env xcrun swift');
      emitter.emitln();
      emitter.emitln('import Cocoa');
    }
    this.emitInclude(emitter);
    outputPars.head = emitter.output;

    /***************************** foot ******************************/
    emitter = new Emitter(this.config);
    if (this.config.exec) {
      emitter.emitln();
      emitter.emitln('Client.main(CommandLine.arguments)');
    }
    outputPars.foot = emitter.output;

    /***************************** combine output ******************************/
    const config = _deepClone(this.config);
    config.ext = '.swift';
    config.dir = `${config.dir}`;
    if (!this.config.exec) {
      config.dir = `${config.dir}/Sources/${this.package}`;
    }
    config.filename = object_type === 'model' ? 'Models' : config.clientName || 'Client';
    this.combineOutputParts(config, outputPars);
  }