Class: Ahoy::Generators::ActiverecordGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Ahoy::Generators::ActiverecordGenerator
- Includes:
- ActiveRecord::Generators::Migration
- Defined in:
- lib/generators/ahoy/activerecord_generator.rb
Instance Method Summary collapse
-
#adapter ⇒ Object
use connection_config instead of connection.adapter so database connection isn’t needed.
- #copy_templates ⇒ Object
- #migration_version ⇒ Object
- #properties_type ⇒ Object
- #rails52? ⇒ Boolean
Instance Method Details
#adapter ⇒ Object
use connection_config instead of connection.adapter so database connection isn’t needed
32 33 34 35 36 37 38 |
# File 'lib/generators/ahoy/activerecord_generator.rb', line 32 def adapter if ActiveRecord::VERSION::STRING.to_f >= 6.1 ActiveRecord::Base.connection_db_config.adapter.to_s else ActiveRecord::Base.connection_config[:adapter].to_s end end |
#copy_templates ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/generators/ahoy/activerecord_generator.rb', line 11 def copy_templates template "database_store_initializer.rb", "config/initializers/ahoy.rb" template "active_record_visit_model.rb", "app/models/ahoy/visit.rb" template "active_record_event_model.rb", "app/models/ahoy/event.rb" migration_template "active_record_migration.rb", "db/migrate/create_ahoy_visits_and_events.rb", migration_version: migration_version puts "\nAlmost set! Last, run:\n\n rails db:migrate" end |
#migration_version ⇒ Object
44 45 46 |
# File 'lib/generators/ahoy/activerecord_generator.rb', line 44 def migration_version "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]" end |
#properties_type ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/generators/ahoy/activerecord_generator.rb', line 19 def properties_type case adapter when /postg/i # postgres, postgis "jsonb" when /mysql/i "json" else "text" end end |
#rails52? ⇒ Boolean
40 41 42 |
# File 'lib/generators/ahoy/activerecord_generator.rb', line 40 def rails52? ActiveRecord::VERSION::STRING.to_f >= 5.2 end |