Module: SqAuth::SqAuthIntegration::SqAuthRack

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

Defined Under Namespace

Classes: Middleware

Class Method Summary collapse

Class Method Details

.alter_environment(options = {}) ⇒ 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
# File 'lib/sq_auth/sq_auth_integration/sq_auth_rack.rb', line 7

def self.alter_environment options={}
  if defined?(Rails)
    # Rails::Engine?
    if (Rails.application.nil?)
      options[:engine].instance_eval do
        initializer "Rails::Engine.add_sq_auth" do |app|
          app.middleware.use SqAuth::SqAuthIntegration::SqAuthRack::Middleware
        end
      end
    else
      Rails.application.class.instance_eval do
        # cookie in rails enabled by default
        # config.middleware.use Rack::Session::Cookie, :expire_after => 2592000
        config.middleware.use SqAuth::SqAuthIntegration::SqAuthRack::Middleware
      end
    end
  elsif defined?(Sinatra)
    if options[:klass].respond_to?(:use)
      sinatra_class = options[:klass]
    else
      sinatra_class = Sinatra::Base
    end
    sinatra_class.use Rack::Session::Cookie, :expire_after => 2592000
    sinatra_class.use SqAuth::SqAuthIntegration::SqAuthRack::Middleware
  end
end

.check_environmentObject



4
5
6
# File 'lib/sq_auth/sq_auth_integration/sq_auth_rack.rb', line 4

def self.check_environment
  defined?(Rack)
end