Class: CanvasSync::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- CanvasSync::InstallGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/canvas_sync/generators/install_generator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #autogenerated_migration_warning ⇒ Object
- #autogenerated_model_warning ⇒ Object
-
#generate_migrations_and_models ⇒ Object
Generates the specified models and migrations.
Class Method Details
.next_migration_number(path) ⇒ Object
10 11 12 13 |
# File 'lib/canvas_sync/generators/install_generator.rb', line 10 def self.next_migration_number(path) next_migration_number = current_migration_number(path) + 1 ActiveRecord::Migration.next_migration_number(next_migration_number) end |
Instance Method Details
#autogenerated_migration_warning ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/canvas_sync/generators/install_generator.rb', line 26 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 |
#autogenerated_model_warning ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/canvas_sync/generators/install_generator.rb', line 15 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 |
#generate_migrations_and_models ⇒ Object
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
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/canvas_sync/generators/install_generator.rb', line 44 def generate_migrations_and_models models = ["models"] == "all" ? CanvasSync::SUPPORTED_MODELS : ["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 |