Sha256: 115f9ccfd8bc32ec8b64ae5b76faa868b0226b743e24d2df7c4bb3ba5e16b401

Contents?: true

Size: 1.46 KB

Versions: 7

Compression:

Stored size: 1.46 KB

Contents

# Authlogic bridge for Sinatra
module Authlogic
  module ControllerAdapters
    module SinatraAdapter
      class Cookies
        attr_reader :request, :response

        def initialize(request, response)
          @request = request
          @response = response
        end

        def delete(key, options = {})
          @response.delete_cookie(key, options)
        end

        def []=(key, options)
          @response.set_cookie(key, options)
        end

        def method_missing(meth, *args, &block)
          @request.cookies.send(meth, *args, &block)
        end
      end

      class Controller
        attr_reader :request, :response, :cookies

        def initialize(request, response)
          @request = request
          @cookies = Cookies.new(request, response)
        end

        def session
          env['rack.session']
        end

        def method_missing(meth, *args, &block)
          @request.send meth, *args, &block
        end
      end

      class Adapter < AbstractAdapter
        def cookie_domain
          env['SERVER_NAME']
        end

        module Implementation
          def self.included(klass)
            klass.send :before do
              controller = Controller.new(request, response)
              Authlogic::Session::Base.controller = Adapter.new(controller)
            end
          end
        end
      end
    end
  end
end

Sinatra::Base.send(:include, Authlogic::ControllerAdapters::SinatraAdapter::Adapter::Implementation)

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
authlogic-3.4.6 lib/authlogic/controller_adapters/sinatra_adapter.rb
authlogic-3.4.5 lib/authlogic/controller_adapters/sinatra_adapter.rb
authlogic-3.4.4 lib/authlogic/controller_adapters/sinatra_adapter.rb
authlogic-3.4.3 lib/authlogic/controller_adapters/sinatra_adapter.rb
authlogic-3.4.2 lib/authlogic/controller_adapters/sinatra_adapter.rb
authlogic-3.4.1 lib/authlogic/controller_adapters/sinatra_adapter.rb
authlogic-3.4.0 lib/authlogic/controller_adapters/sinatra_adapter.rb