Sha256: 96ed4815a68a0d10e053830a62c7f42565a6103bccf1ea81fe314ef2d3773870

Contents?: true

Size: 1.97 KB

Versions: 22

Compression:

Stored size: 1.97 KB

Contents

# frozen_string_literal: true
class Hyrax::ModelsGenerator < Rails::Generators::Base
  source_root File.expand_path('../templates', __FILE__)
  argument :model_name, type: :string, default: 'user'
  desc 'This generator makes the following changes to your application:
      1. Copies database migrations
      2. Injects the user behavior onto the user models.
      3. Creates the file_set.rb and collection.rb models.
      4. Generates the clam anti-virus configuration.'

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

  # Setup the database migrations
  def copy_migrations
    rake 'hyrax:install:migrations'
  end

  # Add behaviors to the user model
  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
  # rubocop:enable Metrics/MethodLength

  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

  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

  # Adds clamav initializtion
  def clamav
    generate 'hyrax:clamav'
  end

  private

  def rspec_installed?
    defined?(RSpec) && defined?(RSpec::Rails)
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
hyrax-5.0.0.rc2 lib/generators/hyrax/models_generator.rb
hyrax-5.0.0.rc1 lib/generators/hyrax/models_generator.rb
hyrax-3.6.0 lib/generators/hyrax/models_generator.rb
hyrax-4.0.0 lib/generators/hyrax/models_generator.rb
hyrax-4.0.0.rc3 lib/generators/hyrax/models_generator.rb
hyrax-4.0.0.rc2 lib/generators/hyrax/models_generator.rb
hyrax-4.0.0.rc1 lib/generators/hyrax/models_generator.rb
hyrax-3.5.0 lib/generators/hyrax/models_generator.rb
hyrax-4.0.0.beta2 lib/generators/hyrax/models_generator.rb
hyrax-3.4.2 lib/generators/hyrax/models_generator.rb
hyrax-4.0.0.beta1 lib/generators/hyrax/models_generator.rb
hyrax-3.4.1 lib/generators/hyrax/models_generator.rb
hyrax-3.4.0 lib/generators/hyrax/models_generator.rb
hyrax-3.3.0 lib/generators/hyrax/models_generator.rb
hyrax-3.2.0 lib/generators/hyrax/models_generator.rb
hyrax-3.1.0 lib/generators/hyrax/models_generator.rb
hyrax-3.0.2 lib/generators/hyrax/models_generator.rb
hyrax-3.0.1 lib/generators/hyrax/models_generator.rb
hyrax-3.0.0 lib/generators/hyrax/models_generator.rb
hyrax-3.0.0.pre.rc4 lib/generators/hyrax/models_generator.rb