Skip to content

Commit

Permalink
SPARQL gem monkey-patches Hash#deep_dup and breaks Blacklight's expec…
Browse files Browse the repository at this point in the history
…ted contract with Rails
  • Loading branch information
cbeer committed Jul 23, 2022
1 parent 35cc0a0 commit 63c3cec
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/hyrax/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ class Engine < ::Rails::Engine
message += "It is UNEXPECTED if you are booting up a Hyrax powered application via `rails server'"
Rails.logger.info(message)
end

# Force CatalogController to use our SearchState class, which has an important
# work-around for some highly suspect SPARQL-gem monkeypatching.
CatalogController.search_state_class = Hyrax::SearchState if CatalogController.search_state_class == Blacklight::SearchState
end

initializer 'requires' do
Expand Down
9 changes: 9 additions & 0 deletions lib/hyrax/search_state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,14 @@ def url_for_document(doc, _options = {})
return [hyrax, doc] if doc.collection?
[main_app, doc]
end

# The SPARQL gem stomps on the Rails definition of deep_dup and gives us a Hash instead of
# a HashWithIndifferentAccess. This is an ugly workaround to get the right contract with
# the upstream class.
# https://github.com/ruby-rdf/sparql/blob/develop/lib/sparql/algebra/extensions.rb#L238-L244
def to_hash
super.with_indifferent_access
end
alias to_h to_hash
end
end

0 comments on commit 63c3cec

Please sign in to comment.