Created
December 24, 2016 11:17
-
-
Save ch1c0t/a307589db70f8b161234b745349510e6 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 Hobby | |
module Auth | |
def self.[] *users | |
Module.new do | |
define_singleton_method :included do |app| | |
users.each do |user| | |
app.define_singleton_method user.downcase do |route| | |
action = route.action | |
route.action = -> do | |
if user = (user.find_by_token request.headers['Authorization']) | |
instance_exec &action | |
else | |
response.status = 403 | |
end | |
end | |
end | |
end | |
end | |
end | |
end | |
end | |
end # Ends should be optional. Block nesting can be infered from two-space indent. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment