Module: Sorcery::Controller::Adapters::Sinatra

Defined in:
lib/sorcery/controller/adapters/sinatra.rb

Overview

This module does the magic of translating Rails commands to Sinatra. This way the Rails code doesn’t change, but it actually now calls Sinatra calls.

Defined Under Namespace

Modules: ClassMethods, InstanceMethods, SorceryHelpers Classes: CookieProxy

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/sorcery/controller/adapters/sinatra.rb', line 7

def self.included(base)
  base.class_eval do
    class << self
      # prepend a filter
      def prepend_filter(type, path = nil, options = {}, &block)
        return filters[type].unshift block unless path
        path, options = //, path if path.respond_to?(:each_pair)
        block, *arguments = compile!(type, path, block, options)
        prepend_filter(type) do
          process_route(*arguments) { instance_eval(&block) }
        end
      end

      def after_filter(filter)
        after do
          send(filter)
        end
      end
    end
  end

  ::Sinatra::Request.class_eval do
    def authorization
      env['HTTP_AUTHORIZATION'] ||
          env['X-HTTP_AUTHORIZATION'] ||
          env['X_HTTP_AUTHORIZATION'] ||
          env['REDIRECT_X_HTTP_AUTHORIZATION'] || nil
    end
  end

  base.send(:include, SorceryHelpers)
  base.send(:include, InstanceMethods)
  base.extend(ClassMethods)
end