Sha256: a81287144ec27a309d3bdc05c49ad7bba11adda4778269754e8ccb6adc3294e5

Contents?: true

Size: 755 Bytes

Versions: 7

Compression:

Stored size: 755 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} 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

7 entries across 7 versions & 1 rubygems

Version Path
devise_masquerade-0.1.1 lib/devise_masquerade/controllers/helpers.rb
devise_masquerade-0.1.0 lib/devise_masquerade/controllers/helpers.rb
devise_masquerade-0.0.9 lib/devise_masquerade/controllers/helpers.rb
devise_masquerade-0.0.8 lib/devise_masquerade/controllers/helpers.rb
devise_masquerade-0.0.7 lib/devise_masquerade/controllers/helpers.rb
devise_masquerade-0.0.6 lib/devise_masquerade/controllers/helpers.rb
devise_masquerade-0.0.5 lib/devise_masquerade/controllers/helpers.rb