Sha256: 7e2af3788b3d958bfe575eef784361f1cbe949ae8816aefb1df83c3cc85680ea

Contents?: true

Size: 1.77 KB

Versions: 8

Compression:

Stored size: 1.77 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/models', __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 "create_#{model}.rb", "db/migrate/create_#{model}.rb"
        template "#{model.singularize}.rb", "app/models/#{model.singularize}.rb"
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
canvas_sync-0.3.12 lib/canvas_sync/generators/install_generator.rb
canvas_sync-0.3.11 lib/canvas_sync/generators/install_generator.rb
canvas_sync-0.3.10 lib/canvas_sync/generators/install_generator.rb
canvas_sync-0.3.9 lib/canvas_sync/generators/install_generator.rb
canvas_sync-0.3.8 lib/canvas_sync/generators/install_generator.rb
canvas_sync-0.3.7 lib/canvas_sync/generators/install_generator.rb
canvas_sync-0.3.6 lib/canvas_sync/generators/install_generator.rb
canvas_sync-0.3.5 lib/canvas_sync/generators/install_generator.rb