Class: Ahoy::Generators::ActiverecordGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Ahoy::Generators::ActiverecordGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/generators/ahoy/activerecord_generator.rb
Class Method Summary collapse
-
.next_migration_number(dirname) ⇒ Object
Implement the required interface for Rails::Generators::Migration.
Instance Method Summary collapse
Class Method Details
.next_migration_number(dirname) ⇒ Object
Implement the required interface for Rails::Generators::Migration.
16 17 18 19 20 21 22 23 |
# File 'lib/generators/ahoy/activerecord_generator.rb', line 16 def self.next_migration_number(dirname) #:nodoc: next_migration_number = current_migration_number(dirname) + 1 if ::ActiveRecord::Base. [Time.now.utc.strftime("%Y%m%d%H%M%S"), "%.14d" % next_migration_number].max else "%.3d" % next_migration_number end end |
Instance Method Details
#copy_templates ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/generators/ahoy/activerecord_generator.rb', line 25 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
50 51 52 |
# File 'lib/generators/ahoy/activerecord_generator.rb', line 50 def migration_version "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]" end |
#properties_type ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/generators/ahoy/activerecord_generator.rb', line 33 def properties_type # use connection_config instead of connection.adapter # so database connection isn't needed case ActiveRecord::Base.connection_config[:adapter].to_s when /postg/i # postgres, postgis "jsonb" when /mysql/i "json" else "text" end end |
#rails52? ⇒ Boolean
46 47 48 |
# File 'lib/generators/ahoy/activerecord_generator.rb', line 46 def rails52? ActiveRecord::VERSION::STRING >= "5.2" end |