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
Introduce skip_constants
flag to dsl
#1877
Conversation
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.
This implementation makes sense to me! In terms of naming, how do you feel about exclude_constants
? I can imagine someone seeing one of the existing options named "exclude" and then searching for that, which would help them find this one.
With regards to naming, I would go so far as to say that we should deprecate |
I opted to not use |
I like the idea of eventually deprecating |
lib/tapioca/cli.rb
Outdated
@@ -149,6 +154,7 @@ def dsl(*constant_or_paths) | |||
exclude: options[:exclude], | |||
file_header: options[:file_header], | |||
tapioca_path: TAPIOCA_DIR, | |||
skip_constants: options[:skip_constant], |
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.
This doesn't match the name of the option above, but I would suggest that we name the option as singular anyway.
lib/tapioca/cli.rb
Outdated
@@ -135,6 +135,11 @@ def todo | |||
type: :boolean, | |||
desc: "Halt upon a load error while loading the Rails application", | |||
default: true | |||
option :skip_constants, |
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 suggest this becomes:
option :skip_constants, | |
option :skip_constant, |
since it is primarily meant for skipping a constant but also accepts multiple constants to be specified as part of a single option.
46891d7
to
c532150
Compare
@@ -933,6 +934,7 @@ dsl: | |||
list_compilers: false | |||
app_root: "." | |||
halt_upon_load_error: true | |||
skip_constant: [] |
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.
Decided to go with skip_constant
because I believe differentiating between exclude
option and this one is valuable since exclude
doesn't specify what it's excluding. And to change the name of exclude
option we'd have to go through a deprecation cycle and tell users to update which I believe creates unnecessary work for little benefit.
README.md
Outdated
@@ -500,6 +500,7 @@ Options: | |||
# Default: . | |||
[--halt-upon-load-error], [--no-halt-upon-load-error], [--skip-halt-upon-load-error] # Halt upon a load error while loading the Rails application | |||
# Default: true | |||
[--skip-constant=constant [constant ...]] # Skip the given application constant(s) when generating RBIs |
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.
While the name of the option is okay, I think we should use something else than skip
in the description to better explain what it is doing:
[--skip-constant=constant [constant ...]] # Skip the given application constant(s) when generating RBIs | |
[--skip-constant=constant [constant ...]] # Do not generate RBI definition for the given application constant(s) |
lib/tapioca/commands/abstract_dsl.rb
Outdated
@@ -36,6 +37,7 @@ def initialize( | |||
exclude:, | |||
file_header:, | |||
tapioca_path:, | |||
skip_constant:, |
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 think this could be optional with a default value?
skip_constant:, | |
skip_constant: [], |
@@ -149,6 +154,7 @@ def dsl(*constant_or_paths) | |||
exclude: options[:exclude], | |||
file_header: options[:file_header], | |||
tapioca_path: TAPIOCA_DIR, | |||
skip_constant: options[:skip_constant], |
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.
Should we check that requested_constants
and skip_constant
do not conflict? Or maybe add a note about which one takes precedence?
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.
Since options themselves aren't incompatible I added a detection and warning in the pipeline while looking at its contents.
@@ -124,6 +127,7 @@ def create_pipeline | |||
error_handler: ->(error) { | |||
say_error(error, :bold, :red) | |||
}, | |||
skipped_constants: constantize(@skip_constant), |
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.
Would it make sense to also path ignore_missing
to constantize?
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 think it's useful to tell the user that they are supplying an incorrect constant name so I kept this as is.
spec/tapioca/cli/dsl_spec.rb
Outdated
end | ||
RB | ||
|
||
result = @project.tapioca("dsl --skip-constant Job") |
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.
Let's add a test with more than one value for --skip-constant
so we do not accidentally break this in the future.
There might be need for an escape hatch that will prevent tapioca from generation DSL RBIs for specific constants.
c532150
to
b5f2176
Compare
Motivation
There might be need for an escape hatch that will prevent tapioca from generation DSL RBIs for specific constants.
Implementation
Remove specified constants from the list of processable constants coming from DSL compilers
Tests
Included