I'm working on a platform and they asked me to integrate the Pundit gem. When creating a policy I realized that many methods had the same access control policy. Example:
Action1: Only accessible by the administrator or owner of the resource
Action2: Only accessible by the administrator or owner of the resource
Action3: Only accessible by the administrator or owner of the resource
.
.
.
Then I thought about creating dynamic methods in the following way
[: Action1 ?,: Action2? ,: Action3?].each do |meth|
define_method(meth){@current_user.admin? or @current_user.owner_resource?}
end
But I got a question: Does Ruby on Rails execute the methods at run time or at compile time? Is it optimal to create dynamic methods or is it better to create 3 methods separately in a static way?
Thanks!!!