Module: SqAuth::SqAuthIntegration::SqAuthSinatra

Defined in:
lib/sq_auth/sq_auth_integration/sq_auth_sinatra.rb

Class Method Summary collapse

Class Method Details

.alter_environment(options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/sq_auth/sq_auth_integration/sq_auth_sinatra.rb', line 9

def self.alter_environment options={}
  Sinatra.register SqAuth::SqAuthHelpers::Sinatra
  Sinatra::Base.instance_eval do
    alias :old_get :get
    def get(*args, &block)
      roles = []
      if args[0].is_a?(Array)
        roles << args[0]
        args.shift
      end
      roles.flatten!
      if !roles.empty?
        ok_proc = Proc.new {}
        error_proc = Proc.new do |message|
          throw(:halt, [401, message])
        end
        before(*args) do
          SqAuth.api_filter(roles, ok_proc, error_proc)
        end
      end
      old_get(*args, &block)
    end
  end
end

.check_environmentObject



5
6
7
# File 'lib/sq_auth/sq_auth_integration/sq_auth_sinatra.rb', line 5

def self.check_environment
  defined?(Sinatra)
end