Skip to content
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

819 - refactor use_files.R before adding replace arg #1022

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from

Conversation

ilyaZar
Copy link
Contributor

@ilyaZar ilyaZar commented Apr 3, 2023

To fix #819 , there is the possibility to refactor the internals of use_external_XXX type functions in use_files.R prior to the addition of a new replace arg.

This may or may not be useful; I think it could be, hence the draft PR with some benefits being to reduce duplication

It's easier to add the 'replace'-argument in only one place then (see last commit to this PR).

Essentially all use_external_xxx funcs in use_files.R do the same, so this PR tries to encapsulate identical behaviour into smaller maintainable pieces.

Of course this proposal comes along with quite some work and probably there should be some tests added as well... happy do get on this though!

@VincentGuyader
Copy link
Member

HI,

i prefer overwrite = TRUE, instead of replace = TRUE.
ok for you @ColinFay ?

@ilyaZar ilyaZar force-pushed the 819-use_external_with_replace branch from fc73159 to 558de24 Compare November 29, 2023 13:33
@ilyaZar
Copy link
Contributor Author

ilyaZar commented Nov 29, 2023

Update

Update this PR-branch to be up-to-date with current dev:

  1. change replace-argument name to overwrite
  2. use the following style 7ba820b#diff-c03aab5bb43f6562efff9eeb973b449f684e38dd79aed2b839008ffaeee45a8eR183-R194 for get_new_dir() helper function to throw an error
  3. use check_name_length_is_one instead of check_name_length()
  4. set default value NULL for argument name

Notes:

@ColinFay this PR is a bit of a mess unfortunately as it had to be adjusted to updates made in 7ba820b

But since there is a 100% test coverage for the file R/use_files.R (that has been introduced back then in commit 7ba820b ) it should be rather safe

Let me know if you request any other changes !

Aim:
- reduce duplication
- make long term maintanence easier
- ease the later addition of 'replace'-argument as this needs then
to be done only in one place

How:
- encapsulate internals of use_external_js_file to separate funcs
- re-use separate funcs to reduce duplication in use_external_css_file

Possible To-Dos:
- re-use separate funcs to reduce duplication in
  use_external_html_template
- re-use separate funcs to reduce duplication in use_external_file
- has same structure as use_external_{js,css}_file()
- add check_url_valid
@ilyaZar ilyaZar force-pushed the 819-use_external_with_replace branch 2 times, most recently from 029ecf3 to fc86051 Compare November 29, 2023 14:54
- no dance for use_external_file
- no url check for use_external
- no new-file creation for use_external

Otherwise, same internal structure as other use_external_XXX funcs
default value can be NULL and NULL can be passed as argument
    -> check for both cases
    -> use basename of the URL correctly in this case
`file_path_sans_ext(name)` gets rid of the extension
this must be handled inside tests correctly
@ilyaZar ilyaZar force-pushed the 819-use_external_with_replace branch from fc86051 to 54d1668 Compare November 29, 2023 15:02
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.

None yet

2 participants