Skip to content

Commit

Permalink
Merge pull request #687 from projecthydra-labs/generate_indexer
Browse files Browse the repository at this point in the history
Generate the indexer for a work
  • Loading branch information
jcoyne committed Apr 3, 2017
2 parents a1e2aa4 + 9df4d50 commit 05b3584
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
10 changes: 10 additions & 0 deletions lib/generators/hyrax/work/templates/indexer.rb.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Generated via
# `rails generate hyrax:work <%= class_name %>`
class <%= class_name %>Indexer < Hyrax::WorkIndexer
# Uncomment this block if you want to add custom indexing behavior:
# def generate_solr_document
# super.tap do |solr_doc|
# solr_doc['my_custom_field_ssim'] = object.my_custom_property
# end
# end
end
4 changes: 3 additions & 1 deletion lib/generators/hyrax/work/templates/model.rb.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
class <%= class_name %> < ActiveFedora::Base
include ::Hyrax::WorkBehavior
include ::Hyrax::BasicMetadata

self.indexer = <%= class_name %>Indexer
# Change this to restrict which works can be added as a child.
# self.valid_child_concerns = []
validates :title, presence: { message: 'Your work must have a title.' }

self.human_readable_type = '<%= name.underscore.titleize %>'
end
4 changes: 4 additions & 0 deletions lib/generators/hyrax/work/work_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ def create_controller
template('controller.rb.erb', "app/controllers/hyrax/#{plural_file_name}_controller.rb")
end

def create_indexer
template('indexer.rb.erb', "app/indexers/#{file_name}_indexer.rb")
end

def create_form
template('form.rb.erb', "app/forms/hyrax/#{file_name}_form.rb")
end
Expand Down
2 changes: 2 additions & 0 deletions spec/features/work_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
feature 'Creating a new Work', :workflow do
before do
Rails::Generators.invoke('hyrax:work', ['Catapult', '--quiet'], destination_root: Rails.root)
load "#{EngineCart.destination}/app/indexers/catapult_indexer.rb"
load "#{EngineCart.destination}/app/models/catapult.rb"
load "#{EngineCart.destination}/app/controllers/hyrax/catapults_controller.rb"
load "#{EngineCart.destination}/app/actors/hyrax/actors/catapult_actor.rb"
Expand All @@ -23,5 +24,6 @@
expect(defined? Hyrax::Actors::CatapultActor).to eq 'constant'
expect(defined? Hyrax::CatapultsController).to eq 'constant'
expect(defined? Hyrax::CatapultForm).to eq 'constant'
expect(Catapult.indexer).to eq CatapultIndexer
end
end

0 comments on commit 05b3584

Please sign in to comment.