-
-
Notifications
You must be signed in to change notification settings - Fork 72
YARD fixes + UserSortable concern #2120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Oaphi
wants to merge
5
commits into
develop
Choose a base branch
from
0valt/docs-fixes
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,27 @@ | ||
| module UserSortable | ||
| extend ActiveSupport::Concern | ||
|
|
||
| class_methods do | ||
| # Sort a collection according to a user selection, by mapping user selectable values to column names. | ||
| # SQL injection safe. | ||
| # @param term_opts Hash of search term options | ||
| # @param field_mappings Hash of user-selectable values to column names: +{ age: :created_at, rep: :threshold }+ | ||
| # @option term_opts :term [String] A user-provided search term - usually from +params+, e.g. +params[:sort]+. | ||
| # Should be one of the keys in +field_mappings+. | ||
| # @option term_opts :default [Symbol] A column name to apply as the default sort ordering. | ||
| # @return [ActiveRecord::Relation] A relation of the current type, with the sort ordering applied. | ||
| def user_sort(term_opts, **field_mappings) | ||
| default = term_opts[:default] || :created_at | ||
| requested = term_opts[:term] | ||
| direction = term_opts[:direction] || :desc | ||
| if requested.nil? || field_mappings.exclude?(requested.to_sym) | ||
| $active_search_param = default | ||
| default.is_a?(Symbol) ? order(default => direction) : order(default) | ||
| else | ||
| requested_val = field_mappings[requested.to_sym] | ||
| $active_search_param = requested_val | ||
| requested_val.is_a?(Symbol) ? order(requested_val => direction) : order(requested_val) | ||
| end | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not super-familiar with how all this is wired together, but should this have turned into doc at https://docs.dev.codidact.org/docs/UserSortable? Or am I looking in the wrong place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No clue, those are concerns with
class_methodsinstead ofincluded- that's likely a limitation of yardoc. I can take a look just in case, but pretty sure that's not an issue on our sideThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, different type of method. I don't think we need to fuss over it; I was just trying to figure out if there was an error in either the content or the build setup that we were tripping over. Not that, so fine with me.