Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change define_helpers parameters to String #5492

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ def self.add_mapping(resource, options)
mapping = Devise::Mapping.new(resource, options)
@@mappings[mapping.name] = mapping
@@default_scope ||= mapping.name
@@helpers.each { |h| h.define_helpers(mapping) }
@@helpers.each { |h| h.define_helpers(mapping.name) }
mapping
end

Expand Down
21 changes: 10 additions & 11 deletions lib/devise/controllers/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,31 +109,30 @@ def log_process_action(payload)
# before_action :authenticate_user! # Tell devise to use :user map
# before_action :authenticate_admin! # Tell devise to use :admin map
#
def self.define_helpers(mapping) #:nodoc:
mapping = mapping.name
def self.define_helpers(mapping_name) #:nodoc:

class_eval <<-METHODS, __FILE__, __LINE__ + 1
def authenticate_#{mapping}!(opts = {})
opts[:scope] = :#{mapping}
def authenticate_#{mapping_name}!(opts = {})
opts[:scope] = :#{mapping_name}
warden.authenticate!(opts) if !devise_controller? || opts.delete(:force)
end

def #{mapping}_signed_in?
!!current_#{mapping}
def #{mapping_name}_signed_in?
!!current_#{mapping_name}
end

def current_#{mapping}
@current_#{mapping} ||= warden.authenticate(scope: :#{mapping})
def current_#{mapping_name}
@current_#{mapping_name} ||= warden.authenticate(scope: :#{mapping_name})
end

def #{mapping}_session
current_#{mapping} && warden.session(:#{mapping})
def #{mapping_name}_session
current_#{mapping_name} && warden.session(:#{mapping_name})
end
METHODS

ActiveSupport.on_load(:action_controller) do
if respond_to?(:helper_method)
helper_method "current_#{mapping}", "#{mapping}_signed_in?", "#{mapping}_session"
helper_method "current_#{mapping_name}", "#{mapping_name}_signed_in?", "#{mapping_name}_session"
end
end
end
Expand Down