module Sinatra::ELS::Auth
Public Instance Methods
els_before(opts = {})
click to toggle source
Set up the before hook to use ELS
authentication. Setup ELS
options using set :els_opts
params: opts - Optional hash with a key of either :only, or :except and an array of String values which will be cast into regular expressions. example: # only use els when patch matches "/api/" or anything ending in "/orders" els_before true, :only => ["^\/api\/",".*\/orders$"] # do not use els if the "/util/" path is matched els_before true, :except # use els before everything els_before
when before_all === false all before processing will be ignored
An optional hash of path matchers can be supplied
# File lib/sinatra/els.rb 33 def els_before(opts = {}) 34 before { 35 if opts.key? :only 36 # execute authorize if path matches regex(s) 37 if request.path_info.match(/#{opts[:only].map{|i|"(#{i})"}.join('|')}/) 38 authorize! 39 end 40 elsif opts.key? :except 41 # execute authorize if path doesn't match regex(s) 42 if not request.path_info.match(/#{opts[:except].map{|i|"(#{i})"}.join('|')}/) 43 authorize! 44 end 45 else 46 authorize! 47 end 48 } 49 end