Sha256: 538f2e7ec515764a0de98790f94e48d71758402f39868d130ffadcb6e373b8e0

Contents?: true

Size: 1.1 KB

Versions: 3

Compression:

Stored size: 1.1 KB

Contents

require_relative 'abstract_migration_generator'

class Sufia::UserStatsGenerator < Sufia::AbstractMigrationGenerator
  source_root File.expand_path('../templates', __FILE__)
  argument :model_name, type: :string, default: "user"

  desc """
This generator adds usage stats methods to the user model in your application:
       """

  def banner
    say_status("info", "ADDING USER STATS-RELATED ABILITIES AND TABLES", :blue)
  end

  # Setup the database migrations
  def copy_migrations
    better_migration_template 'create_user_stats.rb'
  end

  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:user_stats client"
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sufia-7.0.0.beta3 lib/generators/sufia/user_stats_generator.rb
sufia-7.0.0.beta2 lib/generators/sufia/user_stats_generator.rb
sufia-7.0.0.beta1 lib/generators/sufia/user_stats_generator.rb