-
-
Save paulcsmith/5727ac9a2db44e3c738948d506b99f90 to your computer and use it in GitHub Desktop.
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
class UserQuery < User::BaseQuery | |
macro safe_sort(default, **scopes) | |
def safe_sort(sort_by : String = {{ default }}) | |
case sort_by | |
{% for key, value in scopes %} | |
when {{ key.stringify }} | |
{{ value.id }} | |
{% end %} | |
else | |
raise "Unknown sorty option #{sort_by}" | |
end | |
end | |
safe_sort default: recently_updated, | |
recently_updated: updated_at.desc_order, | |
recently_created: created_at.desc_order | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment