class Hyrax::DOI::InstallGenerator

Public Instance Methods

generate_config() click to toggle source
# 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_helper() click to toggle source
# 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_document() click to toggle source
# 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_routes() click to toggle source
# 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