Class: Hyrax::ModelsGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Hyrax::ModelsGenerator
- Defined in:
- lib/generators/hyrax/models_generator.rb
Instance Method Summary collapse
- #banner ⇒ Object
-
#clamav ⇒ Object
Adds clamav initializtion.
-
#copy_migrations ⇒ Object
Setup the database migrations.
-
#create_collection ⇒ Object
rubocop:enable Metrics/MethodLength.
- #create_file_set ⇒ Object
-
#inject_user_behavior ⇒ Object
Add behaviors to the user model rubocop:disable Metrics/MethodLength.
Instance Method Details
#banner ⇒ Object
10 11 12 |
# File 'lib/generators/hyrax/models_generator.rb', line 10 def say_status('info', 'GENERATING HYRAX MODELS', :blue) end |
#clamav ⇒ Object
Adds clamav initializtion
50 51 52 |
# File 'lib/generators/hyrax/models_generator.rb', line 50 def clamav generate 'hyrax:clamav' end |
#copy_migrations ⇒ Object
Setup the database migrations
15 16 17 |
# File 'lib/generators/hyrax/models_generator.rb', line 15 def copy_migrations rake 'hyrax:install:migrations' end |
#create_collection ⇒ Object
rubocop:enable Metrics/MethodLength
39 40 41 42 |
# File 'lib/generators/hyrax/models_generator.rb', line 39 def create_collection copy_file 'app/models/collection.rb', 'app/models/collection.rb' copy_file 'spec/models/collection_spec.rb', 'spec/models/collection_spec.rb' if rspec_installed? end |
#create_file_set ⇒ Object
44 45 46 47 |
# File 'lib/generators/hyrax/models_generator.rb', line 44 def create_file_set copy_file 'app/models/file_set.rb', 'app/models/file_set.rb' copy_file 'spec/models/file_set_spec.rb', 'spec/models/file_set_spec.rb' if rspec_installed? end |
#inject_user_behavior ⇒ Object
Add behaviors to the user model rubocop:disable Metrics/MethodLength
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/generators/hyrax/models_generator.rb', line 21 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 |