Last active
November 20, 2015 06:52
-
-
Save vysakh0/bcb718ee35f21354b5f0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#= Bouncers.Bouncer.check_entry(conn, %MyApp.User{}) | |
#=> true | |
defmodule Bouncers.Bouncer do | |
alias Bouncers.Areas | |
def check_entry(conn, resource) do | |
verify(resource, conn.path_info) | |
end | |
defp verify(resource, path) do | |
try do | |
Areas.verify(resource, path) | |
rescue | |
_ -> false | |
end | |
end | |
end | |
defmodule Bouncers.Doors do | |
defmacro bouncer_for(model, allowed_routes) do | |
for route <- allowed_routes do | |
quote bind_quoted: [route: route, resource: model] do | |
def verify(resource, route), do: true | |
end | |
end | |
end | |
end | |
defmodule Bouncers.Areas do | |
require Bouncers.Doors | |
import Bouncers.Doors | |
bouncer_for %MyApp.User{}, [ | |
["api", "users"] | |
] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment