Skip to content

Conversation

@djordjelacmanovic
Copy link
Contributor

@djordjelacmanovic djordjelacmanovic commented Mar 13, 2024

1173

When sorting certain types of attributes, e.g. JSONB values, it is not possible to know ahead of time what attributes to explicitly expose. Introduce prefix-based dynamic sorting so arbitrary sort attributes can be passed to the sort class/proc.

@djordjelacmanovic djordjelacmanovic self-assigned this Mar 13, 2024
When sorting certain types of attributes, e.g. JSONB values, it is not possible to know ahead of time what attributes to explicitly expose. Introduce prefix-based dynamic sorting so arbitrary sort attributes can be passed to the sort class/proc.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces dynamic sorting functionality that allows prefix-based sorting for scenarios where the exact sort attributes cannot be determined ahead of time, such as JSONB values or dynamic data structures.

  • Adds dynamically_sorts_by method to register prefix-based dynamic sort handlers
  • Refactors existing sort system to use Static and Dynamic sort classes for unified handling
  • Introduces DynamicSort base class for implementing custom dynamic sort behavior

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
lib/jsonapi/query_builder/mixins/sort.rb Core implementation of dynamic sorting logic and refactored static sort handling
lib/jsonapi/query_builder/mixins/sort/static.rb New Static sort class for handling traditional fixed-attribute sorting
lib/jsonapi/query_builder/mixins/sort/dynamic.rb New Dynamic sort class for handling prefix-based dynamic sorting
lib/jsonapi/query_builder/dynamic_sort.rb Base class for implementing custom dynamic sort behavior
lib/jsonapi/query_builder.rb Added require for the new DynamicSort class
spec/jsonapi/query_builder/mixins/sort_spec.rb Updated tests to reflect new sort structure and added dynamic sort test coverage
spec/jsonapi/query_builder/mixins/sort/static_spec.rb Test coverage for the new Static sort class
spec/jsonapi/query_builder/mixins/sort/dynamic_spec.rb Test coverage for the new Dynamic sort class
spec/jsonapi/query_builder/dynamic_sort_spec.rb Test coverage for the DynamicSort base class
README.md Documentation explaining dynamic sorting usage with examples

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

djordjelacmanovic and others added 2 commits September 18, 2025 10:48
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@djordjelacmanovic djordjelacmanovic merged commit 9b979e7 into master Sep 18, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants