Skip to content

Commit

Permalink
SearchBuilder#except
Browse files Browse the repository at this point in the history
Just like #append, but removes processor chain methods instead of
appending them.
  • Loading branch information
jrochkind committed Aug 27, 2015
1 parent 52dda97 commit 88c81fe
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/blacklight/search_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,27 @@ def append *addl_processor_chain
builder
end

##
# Converse to append, remove processor chain directives,
# returning a new builder that's a copy of receiver with
# specified change.
#
# Methods in argument that aren't currently in processor
# chain are ignored as no-ops, rather than raising.
def except *except_processor_chain
builder = self.class.new(processor_chain - except_processor_chain, scope)
.with(blacklight_params)
.merge(@merged_params)
.reverse_merge(@reverse_merged_params)

builder.start(@start) if @start
builder.rows(@rows) if @rows
builder.page(@page) if @page
builder.facet(@facet) if @facet

builder
end

##
# Merge additional, repository-specific parameters
def merge extra_params, &block
Expand Down
11 changes: 11 additions & 0 deletions spec/lib/blacklight/search_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@
end
end

describe "#except" do
let(:processor_chain) { [:a, :b, :c, :d, :e] }
it "should provide a new search builder excepting arguments" do
builder = subject.except(:b, :d, :does_not_exist)
expect(builder).not_to equal(subject)
expect(subject.processor_chain).to eq processor_chain
expect(builder.processor_chain).not_to eq subject.processor_chain
expect(builder.processor_chain).to match_array [:a, :c, :e]
end
end

describe "#to_hash" do
it "should append the extra parameters to the result" do
Deprecation.silence(Blacklight::SearchBuilder) do
Expand Down

0 comments on commit 88c81fe

Please sign in to comment.