Skip to content

Instantly share code, notes, and snippets.

@tcocca
Created September 23, 2010 19:40
Show Gist options
  • Save tcocca/594209 to your computer and use it in GitHub Desktop.
Save tcocca/594209 to your computer and use it in GitHub Desktop.
# 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 = method_name.to_s.gsub('logged_in_', '').delete('?').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