-
Notifications
You must be signed in to change notification settings - Fork 0
Add reusable tidy policy constructors and switch request preparation to tidy_policy
#87
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
016e680
Initial plan
Copilot c3702de
chore: outline plan for tidy policy update
Copilot 271986f
feat: add reusable tidy policy constructors
Copilot ac91285
fix: use call in tidy policy helper
Copilot a34aa1f
refactor: simplify tidy policy body helper
Copilot 0bf456a
test: clean up tidy policy review nits
Copilot fddff5b
docs: address tidy policy review feedback
Copilot 3183a70
Refactor `.as_nectar_auth.list()` via realization while implementing …
jonthegeek c066935
Match structure of auth
jonthegeek c9c887a
Apply suggestions from code review
jonthegeek 2633a43
Better default tidy policy.
jonthegeek 945bbec
Call `tidy_policy_body_auto()`, don't pass it unevaluated.
jonthegeek 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
|
jonthegeek marked this conversation as resolved.
|
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
|
jonthegeek marked this conversation as resolved.
|
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
|
jonthegeek marked this conversation as resolved.
|
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,85 @@ | ||
| #' Prepare tidying independent of a request | ||
| #' | ||
| #' This constructor stores a response tidying function and arguments so the same | ||
| #' tidying strategy can be reused across requests. | ||
| #' | ||
| #' @param tidy_fn (`function`) A function that will be invoked by [resp_tidy()] | ||
| #' to tidy a response. | ||
| #' @param ... (`any`) Arguments to pass to `tidy_fn`. | ||
| #' @returns A list with class `"nectar_tidy_policy"` and elements `tidy_fn` and | ||
| #' `tidy_args`. | ||
| #' @family opinionated response parsers | ||
| #' @export | ||
| #' | ||
| #' @examples | ||
| #' tidy_policy_prepare(httr2::resp_body_json, simplifyVector = TRUE) | ||
| tidy_policy_prepare <- function(tidy_fn, ...) { | ||
| tidy_fn <- rlang::as_function(tidy_fn, call = rlang::caller_env()) | ||
| .as_nectar_tidy_policy( | ||
| list(tidy_fn = tidy_fn, tidy_args = rlang::list2(...)) | ||
| ) | ||
| } | ||
|
|
||
| .as_nectar_tidy_policy <- function(tidy_policy, call = rlang::caller_env()) { | ||
| UseMethod(".as_nectar_tidy_policy") | ||
| } | ||
|
|
||
| #' @export | ||
| .as_nectar_tidy_policy.nectar_tidy_policy <- function( | ||
| tidy_policy, | ||
| call = rlang::caller_env() | ||
| ) { | ||
| return(tidy_policy) | ||
| } | ||
|
|
||
| #' @export | ||
| .as_nectar_tidy_policy.NULL <- function( | ||
| tidy_policy, | ||
| call = rlang::caller_env() | ||
| ) { | ||
| return(NULL) | ||
| } | ||
|
|
||
| #' @export | ||
| .as_nectar_tidy_policy.function <- function( | ||
| tidy_policy, | ||
| call = rlang::caller_env() | ||
| ) { | ||
| .as_nectar_tidy_policy(list(tidy_fn = tidy_policy), call = call) | ||
| } | ||
|
|
||
| #' @export | ||
| .as_nectar_tidy_policy.list <- function( | ||
| tidy_policy, | ||
| call = rlang::caller_env() | ||
| ) { | ||
| if (!("tidy_fn" %in% names(tidy_policy))) { | ||
| return(NextMethod()) | ||
| } | ||
| tidy_args <- stbl::to_lst(tidy_policy$tidy_args) %||% list() | ||
| structure( | ||
| list( | ||
| tidy_fn = tidy_policy$tidy_fn, | ||
| tidy_args = c( | ||
| tidy_args, | ||
| tidy_policy[setdiff(names(tidy_policy), c("tidy_fn", "tidy_args"))] | ||
| ) | ||
| ), | ||
| class = "nectar_tidy_policy" | ||
| ) | ||
| } | ||
|
|
||
| #' @export | ||
| .as_nectar_tidy_policy.default <- function( | ||
| tidy_policy, | ||
| call = rlang::caller_env() | ||
| ) { | ||
| .nectar_abort( | ||
| c( | ||
| "{.arg {tidy_policy}} must be `NULL` or a {.cls nectar_tidy_policy}.", | ||
| x = "{.arg {tidy_policy}} is {.obj_type_friendly {tidy_policy}}." | ||
| ), | ||
| subclass = "unsupported_tidy_policy_class", | ||
| call = call | ||
| ) | ||
|
jonthegeek marked this conversation as resolved.
|
||
| } | ||
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.