Class: Kudos::Generators::ActiveRecordGenerator

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.migration_versionObject



19
20
21
# File 'lib/generators/kudos/active_record_generator.rb', line 19

def self.migration_version
  "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]" if requires_migration_number?
end

.next_migration_number(dirname) ⇒ Object



15
16
17
# File 'lib/generators/kudos/active_record_generator.rb', line 15

def self.next_migration_number(dirname)
  ::ActiveRecord::Generators::Base.next_migration_number(dirname)
end

.requires_migration_number?Boolean

Returns:

  • (Boolean)


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

def self.requires_migration_number?
  Rails::VERSION::MAJOR.to_i >= 6
end

Instance Method Details

#create_migration_fileObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/generators/kudos/active_record_generator.rb', line 27

def create_migration_file
  @user_model_name = name.underscore

  migration_template 'migration.erb', 'db/migrate/create_kudos_tables.rb'
  template 'achievement_group.erb', 'app/models/kudos/achievement_group.rb'
  template 'achievement.erb', 'app/models/kudos/achievement.rb'
  template 'users_achievement.erb', 'app/models/kudos/users/achievement.rb'
  template 'achievementable.erb', 'app/models/concerns/kudos/achievementable.rb'
  template 'uuidable.erb', 'app/models/concerns/kudos/uuidable.rb'
end

#migration_versionObject



38
39
40
# File 'lib/generators/kudos/active_record_generator.rb', line 38

def migration_version
  self.class.migration_version
end