π Parent Note
banken is ...,
Simple and lightweight authorization library for Rails inspired by Pundit. Banken provides a set of helpers which restricts what resources a given user is allowed to access.
π€ Situation
Authorization will be grown with your app, and it will be like this.
new? refers show?, show? refers index?.
class BooksLoyalty < ApplicationLoyalty
def index?
@user_context.user == @record.user
end
def show?
index?
end
def new?
show?
end
end
π Solution
Because each method is the same, they don't transfer their logic. Then, define_method
may be nice.
class BooksLoyalty < ApplicationLoyalty
[:index?, :show?, :new?].each do |method|
define_method method do
@user_context.user == @record.user
end
end
end
If you need arguments, see also π my github note.
Top comments (0)