Class: PgRls::Generators::ActiveRecordGenerator
- Inherits:
-
ActiveRecord::Generators::ModelGenerator
- Object
- ActiveRecord::Generators::ModelGenerator
- PgRls::Generators::ActiveRecordGenerator
- Defined in:
- lib/generators/pg_rls/active_record/active_record_generator.rb
Overview
Active Record Generator
Instance Method Summary collapse
- #backport_migration_file ⇒ Object
-
#check_class_collision ⇒ Object
Need to override so it will not check for class collision.
- #create_migration_file ⇒ Object
- #create_model_file ⇒ Object
- #upgrade_migration_file ⇒ Object
- #upgrade_model_file ⇒ Object
Instance Method Details
#backport_migration_file ⇒ Object
54 55 56 57 58 59 |
# File 'lib/generators/pg_rls/active_record/active_record_generator.rb', line 54 def backport_migration_file return if skip_migration_creation? || installing? || !class_coalescing? migration_template "db/migrate/backport_pg_rls_table.rb", "db/migrate/backport_pg_rls_to_#{table_name}.rb" end |
#check_class_collision ⇒ Object
Need to override so it will not check for class collision
19 20 21 22 23 24 |
# File 'lib/generators/pg_rls/active_record/active_record_generator.rb', line 19 def check_class_collision super @class_coalescing = false rescue Rails::Generators::Error @class_coalescing = true end |
#create_migration_file ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/generators/pg_rls/active_record/active_record_generator.rb', line 39 def create_migration_file return if skip_migration_creation? || class_coalescing? clean_indexes_attributes! migration_template "db/migrate/create_#{migration_template_prefix}_table.rb", "db/migrate/create_#{migration_template_prefix}_#{table_name}.rb" end |
#create_model_file ⇒ Object
26 27 28 29 30 31 |
# File 'lib/generators/pg_rls/active_record/active_record_generator.rb', line 26 def create_model_file return if class_coalescing? generate_abstract_class if database && !custom_parent? template("app/models/model.rb", model_path, parent_class_name: parent_class_name) end |
#upgrade_migration_file ⇒ Object
47 48 49 50 51 52 |
# File 'lib/generators/pg_rls/active_record/active_record_generator.rb', line 47 def upgrade_migration_file return if skip_migration_creation? || !class_coalescing? migration_template "db/migrate/convert_to_#{migration_template_prefix}_table.rb", "db/migrate/convert_to_#{migration_template_prefix}_#{table_name}.rb" end |
#upgrade_model_file ⇒ Object
33 34 35 36 37 |
# File 'lib/generators/pg_rls/active_record/active_record_generator.rb', line 33 def upgrade_model_file return unless class_coalescing? && model_file_exists? gsub_file(model_path, /< ApplicationRecord/, "< #{parent_class_name}") end |