Class: Hyrax::ModelsGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/hyrax/models_generator.rb

Instance Method Summary collapse

Instance Method Details



11
12
13
# File 'lib/generators/hyrax/models_generator.rb', line 11

def banner
  say_status('info', 'GENERATING HYRAX MODELS', :blue)
end

#clamavObject

Adds clamav initializtion



41
42
43
# File 'lib/generators/hyrax/models_generator.rb', line 41

def clamav
  generate 'hyrax:clamav'
end

#copy_migrationsObject

Setup the database migrations



16
17
18
19
# File 'lib/generators/hyrax/models_generator.rb', line 16

def copy_migrations
  rake 'hyrax:install:migrations'
  rake 'valkyrie_engine:install:migrations'
end

#inject_user_behaviorObject

Add behaviors to the user model



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

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