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
Initial support for ActiveRecord enums (and other things, too) #1618
Conversation
ba541af
to
5d26917
Compare
for efficiency
5d26917
to
e445736
Compare
e445736
to
1920a23
Compare
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.
Thank you for great PR 🎉
I'm not a maintainer but I was a little worried 😄 🙏
arg = call.first_arg | ||
return unless hash? arg | ||
|
||
enum_name = arg[1].value # first key |
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 line raises WrongSexpError: Sexp#value called on multi-item Sexp
if arg[1]
is string interpolation like the followings. Unfortunately our project contains this rare case 😢
%i[a b].each do |prefix|
enum "#{prefix}_column" => [...]
end
end | ||
|
||
enum_method = s(:defn, enum_name, s(:args), safe_literal(call_line)) | ||
enums_method = s(:defs, s(:self), enums_name, s(:args), enum_values) |
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 may be wrong but I think that enum_values
have to take into consideration _prefix/_suffix
options.
https://api.rubyonrails.org/v5.2.3/classes/ActiveRecord/Enum.html
enum(item_type: %i[digital]) #=> define digital
enum(item_type: %i[digital], _prefix: true) #=> define item_type_digital
Tired of splitting this into separate PRs, so here we go!
For very simple, obvious class methods, Brakeman will now pull out the return value:
This PR also builds on that to support use of ActiveRecord
enum
, which essentially just defining a number of methods that return constant values or booleans.Additionally:
pluralize
is slightly better now (status
->statuses
instead ofstatuss
)Hash#include?