-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #245 from samvera-labs/extendable_query_services
Add an extendable query interface.
- Loading branch information
Showing
8 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
valkyrie/lib/valkyrie/persistence/custom_query_container.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
module Valkyrie::Persistence | ||
class CustomQueryContainer | ||
attr_reader :query_service, :query_handlers | ||
def initialize(query_service:) | ||
@query_service = query_service | ||
@query_handlers = [] | ||
end | ||
|
||
def register_query_handler(query_handler) | ||
@query_handlers << query_handler | ||
end | ||
|
||
def method_missing(meth_name, *args, &block) | ||
query_handler = find_query_handler(meth_name).new(query_service: query_service) | ||
return super unless query_handler | ||
query_handler.__send__(meth_name, *args, &block) | ||
end | ||
|
||
def find_query_handler(method) | ||
query_handlers.find { |x| x.queries.include?(method) } | ||
end | ||
|
||
def respond_to_missing?(meth_name, _args) | ||
find_query_handler(meth_name).present? | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters