Sha256: 46188084e86d80dcf4707a0e915a61d8e13c86f50bc20ae6ca6282f2da565448
Contents?: true
Size: 1.77 KB
Versions: 36
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
36 entries across 36 versions & 1 rubygems