Class: Hydra::HeadGenerator

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

Instance Method Summary collapse

Instance Method Details

#add_gemsObject

Config Files & Initializers



25
26
27
28
29
30
31
32
33
34
# File 'lib/generators/hydra/head_generator.rb', line 25

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_filesObject

Copy all files in templates/config directory to host config



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/generators/hydra/head_generator.rb', line 65

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_configurationObject



83
84
85
86
87
88
89
90
# File 'lib/generators/hydra/head_generator.rb', line 83

def create_conneg_configuration
  file_path = "config/initializers/mime_types.rb"
  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_behaviorObject

Add Hydra to the application controller



51
52
53
54
55
# File 'lib/generators/hydra/head_generator.rb', line 51

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_search_builder_behaviorObject

Add Hydra to the SearchBuilder



58
59
60
61
62
# File 'lib/generators/hydra/head_generator.rb', line 58

def inject_hydra_search_builder_behavior
  insert_into_file "app/models/search_builder.rb", after: "include Blacklight::Solr::SearchBuilderBehavior\n" do
    "  include Hydra::AccessControlsEnforcement\n"
  end
end

#inject_hydra_user_behaviorObject

Add Hydra behaviors to the user model



103
104
105
106
107
108
109
110
111
112
113
# File 'lib/generators/hydra/head_generator.rb', line 103

def inject_hydra_user_behavior
  file_path = "app/models/#{model_name.underscore}.rb"
  if File.exists?(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_connegObject



92
93
94
95
96
97
98
99
100
# File 'lib/generators/hydra/head_generator.rb', line 92

def inject_solr_document_conneg
  file_path = "app/models/solr_document.rb"
  if File.exists?(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

#inject_test_frameworkObject



36
37
38
39
40
41
42
43
44
# File 'lib/generators/hydra/head_generator.rb', line 36

def inject_test_framework
  return if options[:'skip-rspec']

  application("\n" <<
    "    config.generators do |g|\n" <<
    "      g.test_framework :rspec, :spec => true\n" <<
    "    end\n\n"
  )
end

#overwrite_catalog_controllerObject



46
47
48
# File 'lib/generators/hydra/head_generator.rb', line 46

def overwrite_catalog_controller
  copy_file "catalog_controller.rb", "app/controllers/catalog_controller.rb"
end