Sha256: f549386f442215fb698c2aca2d5042507019aa958665515c5b5876dc6fae7aee

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

Ponytail.Models.MigrationFile = Backbone.Model.extend({
  defaults: {
    className: "",
    rawContent: "",
  },
  initialize: function(attrs, options) {
    this.tables = [];
    this.bind("change:className", this.update);
  },
  updateByTables: function(tables) {
    this.tables = tables;
    this.update();
  },
  update: function() {
    var rawContent = [
      "class " + this.get("className") + " < ActiveRecord::MigrationFile",
      this.getContentOfClass(),
      "end",
    ].join("\n");
    this.set({"rawContent": rawContent});
  },
  getContentOfClass: function() {
    return _.compact([
      "def change",
      this.getStringOfCommands(),
      "end",
    ]).join("\n").replace(/^/, "  ").replace(/\n/g, "\n  ");
  },
  getStringOfCommands: function() {
    var commands = this.getCommands();
    return commands.map(function(command) {
      return command.toString();
    }).join("\n").replace(/^/, "  ").replace(/\n/g, "\n  ");
  },
  getCommands: function() {
    return _.flatten(this.tables.map(function(table) {
      return table.getCommands();
    }));
  },
});

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ponytail-0.3.0 app/assets/javascripts/ponytail/models/migration_file.js