Sha256: e77a986fb7df2e08a45f8e96e9e8815ab9a6907df14224f5775955e46c1ff49f

Contents?: true

Size: 1.79 KB

Versions: 79

Compression:

Stored size: 1.79 KB

Contents

require "rails/generators"
require "rails/generators/migration"

module CanvasSync
  class InstallGenerator < Rails::Generators::Base
    include Rails::Generators::Migration
    source_root File.expand_path("../templates", __FILE__)
    class_option :models, type: :string, required: true

    def self.next_migration_number(path)
      next_migration_number = current_migration_number(path) + 1
      ActiveRecord::Migration.next_migration_number(next_migration_number)
    end

    def autogenerated_model_warning
      <<-HERE.strip_heredoc
        #
        # AUTO GENERATED MODEL
        # This model was auto generated by the CanvasSync Gem.
        # You can customize it as needed, but make sure you test
        # any changes you make to the auto generated methods.
        #
      HERE
    end

    def autogenerated_migration_warning
      <<-HERE.strip_heredoc
        #
        # AUTO GENERATED MIGRATION
        # This migration was auto generated by the CanvasSync Gem.
        # You can add new columns to this table, but removing or
        # re-naming ones created here may break Canvas Syncing.
        #
      HERE
    end

    # Generates the specified models and migrations. Invoke with:
    #
    # bin/rails generate canvas_sync:install --models users,courses
    #
    # Install all models and migrations with:
    #
    # bin/rails generate canvas_sync:install --models all
    def generate_migrations_and_models
      models = options["models"] == "all" ? CanvasSync::SUPPORTED_MODELS : options["models"].split(",")
      CanvasSync.validate_models!(models)

      models.each do |model|
        migration_template "migrations/create_#{model}.rb", "db/migrate/create_#{model}.rb"
        template "models/#{model.singularize}.rb", "app/models/#{model.singularize}.rb"
      rescue
      end
    end
  end
end

Version data entries

79 entries across 79 versions & 1 rubygems

Version Path
canvas_sync-0.22.6 lib/canvas_sync/generators/install_generator.rb
canvas_sync-0.22.5 lib/canvas_sync/generators/install_generator.rb
canvas_sync-0.22.4 lib/canvas_sync/generators/install_generator.rb
canvas_sync-0.22.3 lib/canvas_sync/generators/install_generator.rb
canvas_sync-0.22.2 lib/canvas_sync/generators/install_generator.rb
canvas_sync-0.22.1 lib/canvas_sync/generators/install_generator.rb
canvas_sync-0.22.0 lib/canvas_sync/generators/install_generator.rb
canvas_sync-0.22.0.beta8 lib/canvas_sync/generators/install_generator.rb
canvas_sync-0.22.0.beta7 lib/canvas_sync/generators/install_generator.rb
canvas_sync-0.22.0.beta6 lib/canvas_sync/generators/install_generator.rb
canvas_sync-0.22.0.beta5 lib/canvas_sync/generators/install_generator.rb
canvas_sync-0.22.0.beta4 lib/canvas_sync/generators/install_generator.rb
canvas_sync-0.22.0.beta3 lib/canvas_sync/generators/install_generator.rb
canvas_sync-0.22.0.beta2 lib/canvas_sync/generators/install_generator.rb
canvas_sync-0.22.0.beta1 lib/canvas_sync/generators/install_generator.rb
canvas_sync-0.21.1 lib/canvas_sync/generators/install_generator.rb
canvas_sync-0.21.1.beta1 lib/canvas_sync/generators/install_generator.rb
canvas_sync-0.21.0 lib/canvas_sync/generators/install_generator.rb
canvas_sync-0.21.0.beta5 lib/canvas_sync/generators/install_generator.rb
canvas_sync-0.21.0.beta4 lib/canvas_sync/generators/install_generator.rb