Module: SqAuth::SqAuthHelpers::Sinatra

Includes:
DSL, SinatraDSL
Defined in:
lib/sq_auth/sq_auth_helpers/sq_auth_helpers_sinatra.rb

Instance Method Summary collapse

Methods included from DSL

#access_action, #access_actions, #draw_for, #sq_auth_access

Methods included from SinatraDSL

#execute_for, #show_to

Instance Method Details

#create_filter(roles, options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/sq_auth/sq_auth_helpers/sq_auth_helpers_sinatra.rb', line 7

def create_filter roles, options = {}
  action = nil
  action = [*@sq_auth_actions_only].flatten.first if @sq_auth_actions_only

  if !roles.empty?
    ok_proc = Proc.new {}
    error_proc = Proc.new do |message|
      throw(:halt, [401, message])
    end
    before(action) do
      SqAuth.api_filter(roles, ok_proc, error_proc, options)
    end
  end
end