Closed OmriSama closed 1 month ago
Sorry for the late reply.
I want to know if there are any more efficient ways to refactor this
I don't really have the bandwidth to do a full review here, so my initial suggestion would simply be: if it works, it's likely factored well. Golfing code is likely only going to help if driven by tests and specific needs. If you're using a linter that you're happy with, and the linter is happy with it, you should be fine. Generally speaking this is how you would approach the problem.
- Is there an easier/built in way to get kwargs/options from a method call other than what I did?
Reading from the parameters of the AST is the correct way.
- Are all the potential SCOPES outlined/defined elsewhere? Rubocop was yelling at me to define them in a constant/variable
I'm not really sure what Rubocop would be asking for here but generally scopes are not defined in any specific place. Note that :module
is not a scope in YARD, just %i(instance class)
are typically used.
- Is there a way to be able to eval individual AstNodes if they're safe? Things like primitives and others... also being able to evaluate instance, class variables, constants etc. in the scope of the current namespace
You have .source
and on nodes which you can always resolve to code if you truly need to eval. My general recommendation would be to avoid doing this if possible, but it's ultimately a decision you need to make and depends on your risk tolerance level of the library, expected contexts, etc. Generally speaking, rubydoc doesn't whitelist any YARD plugins on the output generation side that make use of eval since they can introduce new attack vectors, but that's just one consideration.
Hope some of this helps.
Hello @lsegal and other maintainers
I've spent the last ~12 straight hours or so writing a Handler for
mattr/cattr_accessor
in Rails as I was unsatisfied with the code for the ones I could find.This lead me down a giant rabbit hole, and this is what I've come with:
I want to know if there are any more efficient ways to refactor this, since this was my first foray into the library.
I also want to know:
SCOPES
outlined/defined elsewhere? Rubocop was yelling at me to define them in a constant/variableeval
individualAstNodes
if they're safe? Things like primitives and others... also being able to evaluate instance, class variables, constants etc. in the scope of the currentnamespace
Thanks in advance!