Class: RollupsGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
ActiveRecord::Generators::Migration
Defined in:
lib/generators/rollups_generator.rb

Overview

use rollups instead of rollup:install to avoid class Rollup < ActiveRecord::Base also works out nicely since it’s the gem name

Instance Method Summary collapse

Instance Method Details

#adapterObject



27
28
29
# File 'lib/generators/rollups_generator.rb', line 27

def adapter
  ActiveRecord::Base.connection_db_config.adapter.to_s
end

#copy_templatesObject



10
11
12
# File 'lib/generators/rollups_generator.rb', line 10

def copy_templates
  migration_template migration_source, "db/migrate/create_rollups.rb", migration_version: migration_version
end

#migration_sourceObject



14
15
16
17
18
19
20
21
# File 'lib/generators/rollups_generator.rb', line 14

def migration_source
  case adapter
  when /postg/i
    "dimensions.rb"
  else
    "standard.rb"
  end
end

#migration_versionObject



23
24
25
# File 'lib/generators/rollups_generator.rb', line 23

def migration_version
  "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
end