Sha256: 6adbae064fae9a7767024642353a573c39626f767dca42a4ac35a4fb43a6474a

Contents?: true

Size: 1.31 KB

Versions: 31

Compression:

Stored size: 1.31 KB

Contents

module GoogleAuthenticatorRails
  module Session
    module Activation
      class ControllerMissingError < StandardError; end

      def self.included(klass)
        klass.class_eval do 
          extend  ClassMethods
          include InstanceMethods
        end
      end

    end

    module ClassMethods
      # Every thread in Passenger handles only a single request at a time, but there can be many threads running.  
      # This ensures that when setting the current active controller
      # it only gets set for the current active thread (and doesn't mess up any other threads).
      # 
      def controller=(controller)
        Thread.current[:google_authenticator_rails_controller] = controller
      end

      def controller
        Thread.current[:google_authenticator_rails_controller]
      end

      # If the controller isn't set, we can't use the Sessions.  They rely on the session information passed
      # in from ActionController to access the cookies.
      # 
      def activated?
        !controller.nil?
      end
    end

    module InstanceMethods
      attr_reader :record

      def initialize(record)
        raise Activation::ControllerMissingError unless self.class.activated?

        @record = record
      end

      private
      def controller
        self.class.controller
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
google-authenticator-rails-3.4.3 lib/google-authenticator-rails/session/activation.rb
google-authenticator-rails-3.4.2 lib/google-authenticator-rails/session/activation.rb
google-authenticator-rails-3.4.1 lib/google-authenticator-rails/session/activation.rb
google-authenticator-rails-3.4.0 lib/google-authenticator-rails/session/activation.rb
google-authenticator-rails-3.3.1 lib/google-authenticator-rails/session/activation.rb
google-authenticator-rails-3.3.0 lib/google-authenticator-rails/session/activation.rb
google-authenticator-rails-3.2.1 lib/google-authenticator-rails/session/activation.rb
google-authenticator-rails-3.2.0 lib/google-authenticator-rails/session/activation.rb
google-authenticator-rails-3.1.0 lib/google-authenticator-rails/session/activation.rb
google-authenticator-rails-3.0.0 lib/google-authenticator-rails/session/activation.rb
google-authenticator-rails-1.7.0 lib/google-authenticator-rails/session/activation.rb
google-authenticator-rails-2.0.0 lib/google-authenticator-rails/session/activation.rb
google-authenticator-rails-1.5.1 lib/google-authenticator-rails/session/activation.rb
google-authenticator-rails-1.6.1 lib/google-authenticator-rails/session/activation.rb
google-authenticator-rails-1.6.0 lib/google-authenticator-rails/session/activation.rb
google-authenticator-rails-1.5.0 lib/google-authenticator-rails/session/activation.rb
google-authenticator-rails-1.4.1 lib/google-authenticator-rails/session/activation.rb
google-authenticator-rails-1.4.0 lib/google-authenticator-rails/session/activation.rb
google-authenticator-rails-1.3.0 lib/google-authenticator-rails/session/activation.rb
google-authenticator-rails-1.2.1 lib/google-authenticator-rails/session/activation.rb