Class: ActiveRecord::Generators::FastTreeGenerator
- Inherits:
-
Base
- Object
- Base
- ActiveRecord::Generators::FastTreeGenerator
- Includes:
- FastTree::Generators::OrmHelpers
- Defined in:
- lib/generators/active_record/fast_tree_generator.rb
Instance Method Summary collapse
- #copy_fast_tree_migration ⇒ Object
- #generate_model ⇒ Object
- #migration_data ⇒ Object
- #migration_version ⇒ Object
- #postgresql? ⇒ Boolean
- #rails5? ⇒ Boolean
Instance Method Details
#copy_fast_tree_migration ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/generators/active_record/fast_tree_generator.rb', line 12 def copy_fast_tree_migration if (behavior == :invoke && model_exists?) || (behavior == :revoke && migration_exists?(table_name)) migration_template "migration_existing.rb", "db/migrate/add_fast_tree_to_#{table_name}.rb", migration_version: migration_version else migration_template "migration.rb", "db/migrate/fast_tree_create_#{table_name}.rb", migration_version: migration_version end end |
#generate_model ⇒ Object
20 21 22 |
# File 'lib/generators/active_record/fast_tree_generator.rb', line 20 def generate_model invoke "active_record:model", [name], migration: false unless model_exists? && behavior == :invoke end |
#migration_data ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/generators/active_record/fast_tree_generator.rb', line 24 def migration_data <<RUBY ## Pointers t.integer :l_ptr t.integer :r_ptr t.integer :depth RUBY end |
#migration_version ⇒ Object
42 43 44 45 46 |
# File 'lib/generators/active_record/fast_tree_generator.rb', line 42 def migration_version if rails5? "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]" end end |
#postgresql? ⇒ Boolean
37 38 39 40 |
# File 'lib/generators/active_record/fast_tree_generator.rb', line 37 def postgresql? config = ActiveRecord::Base.configurations[Rails.env] config && config['adapter'] == 'postgresql' end |
#rails5? ⇒ Boolean
33 34 35 |
# File 'lib/generators/active_record/fast_tree_generator.rb', line 33 def rails5? Rails.version.start_with? '5' end |