Created
December 16, 2009 23:40
-
-
Save divoxx/258347 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
module SymbolWithArgs | |
def args | |
@args || [] | |
end | |
def [](*args) | |
@args = args | |
self | |
end | |
end | |
class Symbol | |
include SymbolWithArgs | |
end |
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
def show_only_to(user, *roles) | |
if roles.any? { |role| user.send("is_#{role}?", *role.args) } | |
yield | |
end | |
end | |
# This will only yield if one of this methods returns true: | |
# * user.is_admin? | |
# * user.is_manager_of(other_user) | |
# * user.is_employee_of(some_office) | |
show_only_to current_user, :admin, :manager_of[other_user], :employee_of[some_office] do | |
# some private stuff here | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment