Sha256: 55043723f38404145bce9770925630458a5ef1427e5cd6e333b409a98db57797

Contents?: true

Size: 617 Bytes

Versions: 1

Compression:

Stored size: 617 Bytes

Contents

require "current_me/version"
require File.join(File.dirname(__FILE__), 'current_me', 'railtie') if defined?(Rails::Railtie)

module CurrentMe
  extend ActiveSupport::Concern

  included do
    helper_method :me, :me?
  end

  def me
    if id = session[:me]
      @me ||= User.find(id)
    end
  rescue ActiveRecord::RecordNotFound
    self.me = nil
  end

  def me?
    !!me
  end

  def me!(url)
    redirect_to url unless me?
  end

  def sign_in(user)
    self.me = user
  end

  def me=(user)
    reset_session

    session[:me] = user.id if user
    @me = user
  end

  def sign_out
    self.me = nil
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
current_me-0.0.3 lib/current_me.rb