Class: Hyrax::DOI::AddToWorkTypeGenerator
- Inherits:
-
Rails::Generators::NamedBase
- Object
- Rails::Generators::NamedBase
- Hyrax::DOI::AddToWorkTypeGenerator
- Includes:
- Rails::Generators::ModelHelpers
- Defined in:
- lib/generators/hyrax/doi/add_to_work_type_generator.rb
Instance Method Summary collapse
Instance Method Details
#inject_into_form ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# 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 [: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 ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# 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 [: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 ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# 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 [: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 |