Class: Hyrax::DOI::InstallGenerator

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

Instance Method Summary collapse

Instance Method Details

#generate_configObject



20
21
22
23
24
25
26
27
28
# File 'lib/generators/hyrax/doi/install_generator.rb', line 20

def generate_config
  # rubocop:disable Style/RedundantSelf
  # For some reason I had to use self.destination_root here to get all contexts to work (calling from hyrax app, calling from this engine to test app, rspec tests)
  self.destination_root = Rails.root if self.destination_root.blank? || self.destination_root == Hyrax::DOI::Engine.root.to_s
  initializer_file = File.join(self.destination_root, 'config', 'initializers', 'hyrax-doi.rb')
  # rubocop:enable Style/RedundantSelf

  copy_file "config/initializers/hyrax-doi.rb", initializer_file
end

#inject_into_helperObject



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/generators/hyrax/doi/install_generator.rb', line 30

def inject_into_helper
  # rubocop:disable Style/RedundantSelf
  # For some reason I had to use self.destination_root here to get all contexts to work (calling from hyrax app, calling from this engine to test app, rspec tests)
  self.destination_root = Rails.root if self.destination_root.blank? || self.destination_root == Hyrax::DOI::Engine.root.to_s
  helper_file = File.join(self.destination_root, 'app', 'helpers', "hyrax_helper.rb")
  # rubocop:enable Style/RedundantSelf

  insert_into_file helper_file, after: 'include Hyrax::HyraxHelperBehavior' do
    "\n" \
    "  # Helpers provided by hyrax-doi plugin.\n" \
    "  include Hyrax::DOI::HelperBehavior"
  end
end

#inject_into_solr_documentObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/generators/hyrax/doi/install_generator.rb', line 44

def inject_into_solr_document
  # rubocop:disable Style/RedundantSelf
  # For some reason I had to use self.destination_root here to get all contexts to work (calling from hyrax app, calling from this engine to test app, rspec tests)
  self.destination_root = Rails.root if self.destination_root.blank? || self.destination_root == Hyrax::DOI::Engine.root.to_s
  solr_document_file = File.join(self.destination_root, 'app', 'models', "solr_document.rb")
  # rubocop:enable Style/RedundantSelf

  insert_into_file solr_document_file, after: 'include Hyrax::SolrDocumentBehavior' do
    "\n" \
    "  # Add attributes for DOIs for hyrax-doi plugin.\n" \
    "  include Hyrax::DOI::SolrDocument::DOIBehavior"
  end

  return unless options[:datacite]

  # DataCite specific behavior
  insert_into_file solr_document_file, after: 'Hyrax::DOI::SolrDocument::DOIBehavior' do
    "\n" \
    "  # Add attributes for DataCite DOIs for hyrax-doi plugin.\n" \
    "  include Hyrax::DOI::SolrDocument::DataCiteDOIBehavior"
  end
end

#mount_engine_routesObject



67
68
69
70
71
# File 'lib/generators/hyrax/doi/install_generator.rb', line 67

def mount_engine_routes
  inject_into_file 'config/routes.rb', after: /mount Hyrax::Engine, at: '\S*'\n/ do
    "  mount Hyrax::DOI::Engine, at: '/doi', as: 'hyrax_doi'\n"
  end
end