Sha256: 5b70e48338eaf939ca700eebdcb9a998a79ff95c163cdf626fde6f305507466b

Contents?: true

Size: 832 Bytes

Versions: 12

Compression:

Stored size: 832 Bytes

Contents

module Draper
  module DeviseHelper
    def sign_in(resource_or_scope, resource = nil)
      scope = begin
        Devise::Mapping.find_scope!(resource_or_scope)
      rescue RuntimeError => e
        # Draper 1.0 didn't require the mapping to exist
        ActiveSupport::Deprecation.warn("#{e.message}.\nUse `sign_in :user, mock_user` instead.", caller)
        :user
      end

      _stub_current_scope scope, resource || resource_or_scope
    end

    def sign_out(resource_or_scope)
      scope = Devise::Mapping.find_scope!(resource_or_scope)
      _stub_current_scope scope, nil
    end

    private

    def _stub_current_scope(scope, resource)
      Draper::ViewContext.current.controller.singleton_class.class_eval do
        define_method "current_#{scope}" do
          resource
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 4 rubygems

Version Path
draper-3.0.0.pre1 lib/draper/test/devise_helper.rb
draper_new-3.0.0 lib/draper/test/devise_helper.rb
sc_core-0.0.7 test/dummy/vendor/bundle/ruby/2.2.0/gems/draper-2.1.0/lib/draper/test/devise_helper.rb
draper-2.1.0 lib/draper/test/devise_helper.rb
draper-2.0.0 lib/draper/test/devise_helper.rb
draper-1.4.0 lib/draper/test/devise_helper.rb
draper-1.3.1 lib/draper/test/devise_helper.rb
draper-1.3.0 lib/draper/test/devise_helper.rb
draper-1.2.1 lib/draper/test/devise_helper.rb
draper-1.2.0 lib/draper/test/devise_helper.rb
jamesgolick-draper-1.1.1a lib/draper/test/devise_helper.rb
draper-1.1.0 lib/draper/test/devise_helper.rb