mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Support options[:defaults] and @scope[:defaults]
similar to support for :constraints
This commit is contained in:
parent
dba8f91f99
commit
1c81a40a76
2 changed files with 13 additions and 5 deletions
|
@ -67,6 +67,9 @@ module Devise
|
|||
@constraints = Hash.new { |h,k| h[k] = k.to_s }
|
||||
@constraints.merge!(options[:constraints] || {})
|
||||
|
||||
@defaults = Hash.new { |h,k| h[k] = k.to_s }
|
||||
@defaults.merge!(options[:defaults] || {})
|
||||
|
||||
@sign_out_via = options[:sign_out_via] || Devise.sign_out_via
|
||||
end
|
||||
|
||||
|
@ -104,6 +107,10 @@ module Devise
|
|||
@constraints
|
||||
end
|
||||
|
||||
def defaults
|
||||
@defaults
|
||||
end
|
||||
|
||||
# Create magic predicates for verifying what module is activated by this map.
|
||||
# Example:
|
||||
#
|
||||
|
|
|
@ -160,6 +160,7 @@ module ActionDispatch::Routing
|
|||
options[:path_prefix] ||= @scope[:path] if @scope[:path].present?
|
||||
options[:path_names] = (@scope[:path_names] || {}).merge(options[:path_names] || {})
|
||||
options[:constraints] = (@scope[:constraints] || {}).merge(options[:constraints] || {})
|
||||
options[:defaults] = (@scope[:defaults] || {}).merge(options[:defaults] || {})
|
||||
|
||||
resources.map!(&:to_sym)
|
||||
|
||||
|
@ -186,7 +187,7 @@ module ActionDispatch::Routing
|
|||
|
||||
devise_scope mapping.name do
|
||||
yield if block_given?
|
||||
with_devise_exclusive_scope mapping.fullpath, mapping.name, mapping.constraints do
|
||||
with_devise_exclusive_scope mapping.fullpath, mapping.name, mapping.constraints, mapping.defaults do
|
||||
routes.each { |mod| send("devise_#{mod}", mapping, mapping.controllers) }
|
||||
end
|
||||
end
|
||||
|
@ -331,12 +332,12 @@ module ActionDispatch::Routing
|
|||
@scope[:path] = path
|
||||
end
|
||||
|
||||
def with_devise_exclusive_scope(new_path, new_as, new_constraints) #:nodoc:
|
||||
old_as, old_path, old_module, old_constraints = @scope[:as], @scope[:path], @scope[:module], @scope[:constraints]
|
||||
@scope[:as], @scope[:path], @scope[:module], @scope[:constraints] = new_as, new_path, nil, new_constraints
|
||||
def with_devise_exclusive_scope(new_path, new_as, new_constraints, new_defaults) #:nodoc:
|
||||
old_as, old_path, old_module, old_constraints, old_defaults = @scope[:as], @scope[:path], @scope[:module], @scope[:constraints], @scope[:defaults]
|
||||
@scope[:as], @scope[:path], @scope[:module], @scope[:constraints], @scope[:defaults] = new_as, new_path, nil, new_constraints, new_defaults
|
||||
yield
|
||||
ensure
|
||||
@scope[:as], @scope[:path], @scope[:module], @scope[:constraints] = old_as, old_path, old_module, old_constraints
|
||||
@scope[:as], @scope[:path], @scope[:module], @scope[:constraints], @scope[:defaults] = old_as, old_path, old_module, old_constraints, old_defaults
|
||||
end
|
||||
|
||||
def raise_no_devise_method_error!(klass) #:nodoc:
|
||||
|
|
Loading…
Reference in a new issue