Class: Ahoy::Stores::Generators::ActiveRecordVisitsGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/ahoy/stores/active_record_visits_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

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_visits_generator.rb', line 17

def self.next_migration_number(dirname) #:nodoc:
  next_migration_number = current_migration_number(dirname) + 1
  if ::ActiveRecord::Base.timestamped_migrations
    [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_migrationObject



26
27
28
29
30
31
# File 'lib/generators/ahoy/stores/active_record_visits_generator.rb', line 26

def copy_migration
  unless options["database"].in?([nil, "postgresql", "postgresql-jsonb"])
    raise Thor::Error, "Unknown database option"
  end
  migration_template "active_record_visits_migration.rb", "db/migrate/create_visits.rb", migration_version: migration_version
end

#create_initializerObject



37
38
39
# File 'lib/generators/ahoy/stores/active_record_visits_generator.rb', line 37

def create_initializer
  template "active_record_initializer.rb", "config/initializers/ahoy.rb"
end

#generate_modelObject



33
34
35
# File 'lib/generators/ahoy/stores/active_record_visits_generator.rb', line 33

def generate_model
  template "active_record_visit_model.rb", "app/models/visit.rb"
end

#migration_versionObject



41
42
43
44
45
# File 'lib/generators/ahoy/stores/active_record_visits_generator.rb', line 41

def migration_version
  if ActiveRecord::VERSION::MAJOR >= 5
    "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
  end
end