Method: Hyrax::ModelsGenerator#inject_user_behavior

Defined in:
lib/generators/hyrax/models_generator.rb

#inject_user_behaviorObject

Add behaviors to the user model



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/generators/hyrax/models_generator.rb', line 20

def inject_user_behavior
  file_path = "app/models/#{model_name.underscore}.rb"
  if File.exist?(file_path)
    inject_into_file file_path, after: /include Hydra\:\:User.*$/ do
      "\n  # Connects this user object to Hyrax behaviors." \
      "\n  include Hyrax::User" \
      "\n  include Hyrax::UserUsageStats\n"
    end
  else
    puts "     \e[31mFailure\e[0m  Hyrax 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 hyrax:models client"
  end
end