class Hydra::HeadGenerator

Public Instance Methods

add_gems() click to toggle source

Config Files & Initializers

# File lib/generators/hydra/head_generator.rb, line 24
def add_gems
  gem_group :development, :test do
    gem "fcrepo_wrapper"
    gem "rspec-rails" unless options[:'skip-rspec']
  end

  Bundler.with_clean_env do
    run "bundle install"
  end
end
create_configuration_files() click to toggle source

Copy all files in templates/config directory to host config

# File lib/generators/hydra/head_generator.rb, line 52
def create_configuration_files

  # Initializers
  template "config/initializers/hydra_config.rb",
           "config/initializers/hydra_config.rb"

  # Role Mappings
  copy_file "config/role_map.yml", "config/role_map.yml"

  # CanCan ability.rb
  copy_file "ability.rb", "app/models/ability.rb"

  # Fedora & Solr YAML files
  invoke('active_fedora:config')

  copy_file 'config/blacklight.yml', force: true
end
create_conneg_configuration() click to toggle source
# File lib/generators/hydra/head_generator.rb, line 70
def create_conneg_configuration
  file_path = "config/initializers/mime_types.rb"
  create_file file_path unless File.exist?(file_path)
  append_to_file file_path do
    "Mime::Type.register \"application/n-triples\", :nt\n" +
    "Mime::Type.register \"application/ld+json\", :jsonld\n" +
    "Mime::Type.register \"text/turtle\", :ttl"
  end
end
inject_hydra_controller_behavior() click to toggle source

Add Hydra to the application controller

# File lib/generators/hydra/head_generator.rb, line 45
def inject_hydra_controller_behavior
  insert_into_file "app/controllers/application_controller.rb", after: "include Blacklight::Controller\n" do
    "  include Hydra::Controller::ControllerBehavior\n"
  end
end
inject_hydra_user_behavior() click to toggle source

Add Hydra behaviors to the user model

# File lib/generators/hydra/head_generator.rb, line 91
def inject_hydra_user_behavior
  file_path = "app/models/#{model_name.underscore}.rb"
  if File.exist?(file_path)
    inject_into_class file_path, model_name.classify do
      "  # Connects this user object to Hydra behaviors.\n" +
      "  include Hydra::User\n\n"
    end
  else
    puts "     \e[31mFailure\e[0m  Hydra requires a user object in order to apply access controls. This generators 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 hydra:head client"
  end
end
inject_solr_document_conneg() click to toggle source
# File lib/generators/hydra/head_generator.rb, line 80
def inject_solr_document_conneg
  file_path = "app/models/solr_document.rb"
  if File.exist?(file_path)
    inject_into_file file_path, :before => /end\Z/ do
      "\n  # Do content negotiation for AF models. \n" +
      "\n  use_extension( Hydra::ContentNegotiation )\n"
    end
  end
end
install_rspec() click to toggle source
# File lib/generators/hydra/head_generator.rb, line 35
def install_rspec
  return if options[:'skip-rspec']
  generate 'rspec:install'
end
overwrite_catalog_controller() click to toggle source
# File lib/generators/hydra/head_generator.rb, line 40
def overwrite_catalog_controller
  copy_file "catalog_controller.rb", "app/controllers/catalog_controller.rb"
end