Skip to content

Commit

Permalink
Move indexer to a class attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Mar 10, 2016
1 parent 097aff9 commit d731c29
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/active_fedora/indexing.rb
Expand Up @@ -15,6 +15,16 @@ module Indexing
autoload :Map
end

included do
# Because the previous method of setting indexer was to override
# the class method, we must ensure that we aren't using the instance
# reader so that the old method still works.
class_attribute :indexer, instance_accessor: false

# This is the default indexer class to use for this model.
self.indexer = IndexingService
end

# Return a Hash representation of this object where keys in the hash are appropriate Solr field names.
# @param [Hash] _solr_doc (optional) Hash to insert the fields into
# @param [Hash] _opts (optional)
Expand Down Expand Up @@ -72,10 +82,6 @@ def index_config
end
end

def indexer
IndexingService
end

def reindex_everything
descendants = descendant_uris(ActiveFedora::Base.id_to_uri(''))
descendants.shift # Discard the root uri
Expand Down
14 changes: 14 additions & 0 deletions spec/unit/indexing_spec.rb
@@ -1,6 +1,20 @@
require 'spec_helper'

describe ActiveFedora::Indexing do
describe '.indexer' do
let(:indexing_class) { Class.new }
let(:klass) { Class.new }
before do
klass.include described_class
end

it "is settable as a class attribute" do
expect(klass.indexer).to eq ActiveFedora::IndexingService
klass.indexer = indexing_class
expect(klass.indexer).to eq indexing_class
end
end

context "internal methods" do
before :all do
class SpecNode
Expand Down

0 comments on commit d731c29

Please sign in to comment.