Sha256: 1656017d786fc75d14a29927b86b574bdb17caf121d559e219eeb3f8eb62acc0

Contents?: true

Size: 705 Bytes

Versions: 1

Compression:

Stored size: 705 Bytes

Contents

module SentientUser
  
  def self.included(base)
    base.class_eval {
      def self.current
        Thread.current[:user]
      end

      def self.current=(o)
        raise(ArgumentError,
            "Expected an object of class '#{self}', got #{o.inspect}") unless (o.is_a?(self) || o.nil?)
        Thread.current[:user] = o
      end
  
      def make_current
        Thread.current[:user] = self
      end

      def current?
        !Thread.current[:user].nil? && self.id == Thread.current[:user].id
      end
    }
  end
end

module SentientController
  def self.included(base)
    base.class_eval {
      before_filter do |c|
        User.current = c.send(:current_user)
      end
    }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sentient_user-0.3.0 lib/sentient_user.rb