Sha256: 82e65a7fe7e80b1d7870767a7b1f35b3394da8facf6fc137b356e9198c7ac093

Contents?: true

Size: 850 Bytes

Versions: 4

Compression:

Stored size: 850 Bytes

Contents

module StrongPresenter
  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)
      StrongPresenter::ViewContext.current.controller.singleton_class.class_eval do
        define_method "current_#{scope}" do
          resource
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
strong_presenter-0.2.2 lib/strong_presenter/test/devise_helper.rb
strong_presenter-0.2.1 lib/strong_presenter/test/devise_helper.rb
strong_presenter-0.2.0 lib/strong_presenter/test/devise_helper.rb
strong_presenter-0.1.0 lib/strong_presenter/test/devise_helper.rb