{"size": 1343, "ext": "js", "max_stars_repo_path": "generators/model/index.js", "max_stars_repo_name": "jorgelaranjo/generator-flask-api", "max_stars_repo_stars_event_min_datetime": "2015-09-01T16:08:52.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-06T09:09:41.000Z", "max_issues_repo_path": "generators/model/index.js", "max_issues_repo_name": "jorgelaranjo/generator-flask-api", "max_issues_repo_issues_event_min_datetime": "2016-04-09T16:56:56.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-30T17:22:25.000Z", "max_forks_repo_path": "generators/model/index.js", "max_forks_repo_name": "jorgelaranjo/generator-flask-api", "max_forks_repo_forks_event_min_datetime": "2016-05-15T02:38:17.000Z", "max_forks_repo_forks_event_max_datetime": "2020-01-14T08:06:34.000Z"}
{"max_stars_count": 83, "max_issues_count": 6, "max_forks_count": 11, "avg_line_length": 23.9821428571, "max_line_length": 72, "alphanum_fraction": 0.6001489203}
'use strict';

var path = require('path');
var chalk = require('chalk');
var AllYourBase = require('../base/AllYourBase');

module.exports = AllYourBase.extend({
  constructor: function () {
    AllYourBase.apply(this, arguments);

    this.argument('name', {
      required: true,
      type: String,
      desc: 'Name of the data model.'
    });
  },

  initializing: function () {
    this.appName = this.config.get('appName');
    this.name = this.name.toLowerCase();
    this.database = this.config.get('database');
    this.databaseMapper = this.config.get('databaseMapper');
  },

  writing: function () {
    var template;
    if (this.databaseMapper === 'sqlalchemy') {
      template = 'sqlalchemy_model.py';
    } else {
      template = 'object_model.py';
    }

    this.fs.copyTpl(
      this.templatePath(template),
      this.destinationPath(path.join(
        this.appName, 'models', this.lodash.snakeCase(this.name) + '.py'
      )),
      {
        database: this.database,
        modelClass: this.lodash.pascalCase(this.name)
      }
    );
  },

  end: function () {
    if (!this.options.isGeneratingResource) {
      this.log(chalk.green('\nAll set!\n'));

      this.log(chalk.cyan(
        'Be sure to import your fancy new model into any endpoints\n' +
          'or schemas that need it.\n'
      ));
    }
  }
});
