Class: Ahoy::Stores::Generators::ActiveRecordEventsGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Ahoy::Stores::Generators::ActiveRecordEventsGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/generators/ahoy/stores/active_record_events_generator.rb
Class Method Summary collapse
-
.next_migration_number(dirname) ⇒ Object
Implement the required interface for Rails::Generators::Migration.
Instance Method Summary collapse
- #copy_migration ⇒ Object
- #create_initializer ⇒ Object
- #detect_database ⇒ Object
- #generate_model ⇒ Object
- #migration_version ⇒ Object
Class Method Details
.next_migration_number(dirname) ⇒ Object
Implement the required interface for Rails::Generators::Migration.
17 18 19 20 21 22 23 24 |
# File 'lib/generators/ahoy/stores/active_record_events_generator.rb', line 17 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_migration ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/generators/ahoy/stores/active_record_events_generator.rb', line 26 def copy_migration @database = ["database"] || detect_database unless @database.in?([nil, "postgresql", "postgresql-jsonb", "mysql", "sqlite"]) raise Thor::Error, "Unknown database option" end migration_template "active_record_events_migration.rb", "db/migrate/create_ahoy_events.rb", migration_version: migration_version end |
#create_initializer ⇒ Object
38 39 40 |
# File 'lib/generators/ahoy/stores/active_record_events_generator.rb', line 38 def create_initializer template "active_record_initializer.rb", "config/initializers/ahoy.rb" end |
#detect_database ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/generators/ahoy/stores/active_record_events_generator.rb', line 42 def detect_database postgresql_version = ActiveRecord::Base.connection.send(:postgresql_version) rescue 0 if postgresql_version >= 90400 "postgresql-jsonb" elsif postgresql_version >= 90200 "postgresql" end end |
#generate_model ⇒ Object
34 35 36 |
# File 'lib/generators/ahoy/stores/active_record_events_generator.rb', line 34 def generate_model template "active_record_event_model.rb", "app/models/ahoy/event.rb" end |
#migration_version ⇒ Object
51 52 53 54 55 |
# File 'lib/generators/ahoy/stores/active_record_events_generator.rb', line 51 def migration_version if ActiveRecord::VERSION::MAJOR >= 5 "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]" end end |