Class: Sufia::Models::UserStatsGenerator

Inherits:
AbstractMigrationGenerator show all
Defined in:
lib/generators/sufia/models/user_stats_generator.rb

Instance Method Summary collapse

Methods inherited from AbstractMigrationGenerator

next_migration_number

Instance Method Details

#add_stats_mixin_to_user_modelObject



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/generators/sufia/models/user_stats_generator.rb', line 20

def add_stats_mixin_to_user_model
  file_path = "app/models/#{model_name.underscore}.rb"

  if File.exist?(file_path)
    inject_into_file file_path, after: /include Sufia\:\:User.*$/ do
      "\n  include Sufia::UserUsageStats"
    end
  else
    puts "     \e[31mFailure\e[0m  Sufia requires a user object. This generator assumes that the model is defined in the file #{file_path}, which does not exist.  If you used a different name, please re-run the generator and provide that name as an argument. Such as \b  rails g sufia:models:user_stats client"
  end
end


11
12
13
# File 'lib/generators/sufia/models/user_stats_generator.rb', line 11

def banner
  say_status("info", "ADDING USER STATS-RELATED ABILITIES TO SUFIA MODELS", :blue)
end

#copy_migrationsObject

Setup the database migrations



16
17
18
# File 'lib/generators/sufia/models/user_stats_generator.rb', line 16

def copy_migrations
  better_migration_template 'create_user_stats.rb'
end