Sha256: fc24b008b4facbcba0706d7d3df88528e37baccd42b47351c9420b1671c80a6f

Contents?: true

Size: 1.13 KB

Versions: 2

Compression:

Stored size: 1.13 KB

Contents

require_relative 'abstract_migration_generator'

class Sufia::Models::UserStatsGenerator < Sufia::Models::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 TO SUFIA MODELS", :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.exists?(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
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sufia-models-6.2.0 lib/generators/sufia/models/user_stats_generator.rb
sufia-models-6.1.0 lib/generators/sufia/models/user_stats_generator.rb