Sha256: 84c3ccb23982a25babbef2868e3ba279138903a1f0c78a7018ec3e1666f90b5e

Contents?: true

Size: 811 Bytes

Versions: 1

Compression:

Stored size: 811 Bytes

Contents

module DeviseMasquerade
  module Controllers
    module Helpers
      def self.define_helpers(mapping)
        name = mapping.name

        class_eval <<-METHODS, __FILE__, __LINE__ + 1
          def masquerade_#{name}!
            return if params[:masquerade].blank?

            #{name} = ::#{name.to_s.classify}.find_by_masquerade_key(params[:masquerade])

            sign_in(#{name}, :bypass => Devise.masquerade_bypass_warden_callback) if #{name}
          end

          def #{name}_masquerade?
            session[:"devise_masquerade_#{name}"].present?
          end
        METHODS

        ActiveSupport.on_load(:action_controller) do
          helper_method "#{name}_masquerade?"
        end
      end
    end
  end
end

ActionController::Base.send(:include, DeviseMasquerade::Controllers::Helpers)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
devise_masquerade-0.1.3 lib/devise_masquerade/controllers/helpers.rb