class Hyrax::DOI::AddToWorkTypeGenerator

Public Instance Methods

inject_into_form() click to toggle source
# File lib/generators/hyrax/doi/add_to_work_type_generator.rb, line 49
def inject_into_form
  # 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
  form_file = File.join(self.destination_root, 'app', 'forms', 'hyrax', *class_path, "#{file_name}_form.rb")
  # rubocop:enable Style/RedundantSelf

  insert_into_file form_file, after: 'Hyrax::Forms::WorkForm' do
    "\n" \
    "    # Adds behaviors for hyrax-doi plugin.\n" \
    "    include Hyrax::DOI::DOIFormBehavior"
  end

  return unless options[:datacite]

  # DataCite specific behavior
  insert_into_file form_file, after: 'include Hyrax::DOI::DOIFormBehavior' do
    "\n" \
    "    # Adds behaviors for DataCite DOIs via hyrax-doi plugin.\n" \
    "    include Hyrax::DOI::DataCiteDOIFormBehavior"
  end
end
inject_into_model() click to toggle source
# File lib/generators/hyrax/doi/add_to_work_type_generator.rb, line 25
def inject_into_model
  # 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
  model_file = File.join(self.destination_root, 'app', 'models', *class_path, "#{file_name}.rb")
  # rubocop:enable Style/RedundantSelf

  insert_into_file model_file, after: 'include ::Hyrax::WorkBehavior' do
    "\n" \
    "  # Adds behaviors for hyrax-doi plugin.\n" \
    "  include Hyrax::DOI::DOIBehavior"
  end

  return unless options[:datacite]

  # DataCite specific behavior
  insert_into_file model_file, after: 'include Hyrax::DOI::DOIBehavior' do
    "\n" \
    "  # Adds behaviors for DataCite DOIs via hyrax-doi plugin.\n" \
    "  include Hyrax::DOI::DataCiteDOIBehavior"
  end
end
inject_into_presenter() click to toggle source
# File lib/generators/hyrax/doi/add_to_work_type_generator.rb, line 73
def inject_into_presenter
  # 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
  presenter_file = File.join(self.destination_root, 'app', 'presenters', 'hyrax', *class_path, "#{file_name}_presenter.rb")
  # rubocop:enable Style/RedundantSelf

  insert_into_file presenter_file, after: '::WorkShowPresenter' do
    "\n" \
    "    # Adds behaviors for hyrax-doi plugin.\n" \
    "    include Hyrax::DOI::DOIPresenterBehavior"
  end

  return unless options[:datacite]

  # DataCite specific behavior
  insert_into_file presenter_file, after: 'include Hyrax::DOI::DOIPresenterBehavior' do
    "\n" \
    "    # Adds behaviors for DataCite DOIs via hyrax-doi plugin.\n" \
    "    include Hyrax::DOI::DataCiteDOIPresenterBehavior"
  end
end