-
-
Save technicalpickles/594297 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# match method names like | |
# logged_id_super_admin_or_admin? | |
# or | |
# logged_in_admin_or_lead? | |
def method_missing(method_name, *args) | |
if method_name.to_s.match(/^logged_in_(.*)?$/) | |
roles = $1.split('_or_') | |
return false unless logged_in? && current_user.company_id == current_company.id | |
roles.each do |role| | |
return false unless send("#{role}_role?") | |
end | |
return true | |
else | |
super | |
end | |
end | |
def super_admin_role? | |
current_user.super_admin? | |
end | |
def admin_role? | |
current_user.is_broker? | |
end | |
def lead_role? | |
current_user.is_lead? | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment