@@ -673,7 +673,7 @@ def default_url_options=(options)
673
673
alias_method :default_url_options , :default_url_options=
674
674
675
675
def with_default_scope ( scope , &block )
676
- scope ( scope ) do
676
+ scope ( ** scope ) do
677
677
instance_exec ( &block )
678
678
end
679
679
end
@@ -883,8 +883,7 @@ module Scoping
883
883
# scope as: "sekret" do
884
884
# resources :posts
885
885
# end
886
- def scope ( *args )
887
- options = args . extract_options! . dup
886
+ def scope ( *args , only : nil , except : nil , **options )
888
887
scope = { }
889
888
890
889
options [ :path ] = args . flatten . join ( "/" ) if args . any?
@@ -905,9 +904,8 @@ def scope(*args)
905
904
block , options [ :constraints ] = options [ :constraints ] , { }
906
905
end
907
906
908
- if options . key? ( :only ) || options . key? ( :except )
909
- scope [ :action_options ] = { only : options . delete ( :only ) ,
910
- except : options . delete ( :except ) }
907
+ if only || except
908
+ scope [ :action_options ] = { only :, except : }
911
909
end
912
910
913
911
if options . key? :anchor
@@ -987,18 +985,16 @@ def controller(controller)
987
985
# namespace :admin, as: "sekret" do
988
986
# resources :posts
989
987
# end
990
- def namespace ( path , options = { } , &block )
991
- path = path . to_s
992
-
993
- defaults = {
994
- module : path ,
995
- as : options . fetch ( :as , path ) ,
996
- shallow_path : options . fetch ( :path , path ) ,
997
- shallow_prefix : options . fetch ( :as , path )
998
- }
988
+ def namespace ( name , as : DEFAULT , path : DEFAULT , shallow_path : DEFAULT , shallow_prefix : DEFAULT , **options , &block )
989
+ name = name . to_s
990
+ options [ :module ] ||= name
991
+ as = name if as == DEFAULT
992
+ path = name if path == DEFAULT
993
+ shallow_path = path if shallow_path == DEFAULT
994
+ shallow_prefix = as if shallow_prefix == DEFAULT
999
995
1000
- path_scope ( options . delete ( : path) { path } ) do
1001
- scope ( defaults . merge! ( options ) , &block )
996
+ path_scope ( path ) do
997
+ scope ( ** options , as : , shallow_path : , shallow_prefix : , &block )
1002
998
end
1003
999
end
1004
1000
@@ -1192,7 +1188,7 @@ module Resources
1192
1188
class Resource # :nodoc:
1193
1189
attr_reader :controller , :path , :param
1194
1190
1195
- def initialize ( entities , api_only , shallow , options = { } )
1191
+ def initialize ( entities , api_only , shallow , only : nil , except : nil , ** options )
1196
1192
if options [ :param ] . to_s . include? ( ":" )
1197
1193
raise ArgumentError , ":param option can't contain colons"
1198
1194
end
@@ -1205,8 +1201,8 @@ def initialize(entities, api_only, shallow, options = {})
1205
1201
@options = options
1206
1202
@shallow = shallow
1207
1203
@api_only = api_only
1208
- @only = options . delete : only
1209
- @except = options . delete : except
1204
+ @only = only
1205
+ @except = except
1210
1206
end
1211
1207
1212
1208
def default_actions
@@ -1285,7 +1281,7 @@ def singleton?; false; end
1285
1281
end
1286
1282
1287
1283
class SingletonResource < Resource # :nodoc:
1288
- def initialize ( entities , api_only , shallow , options )
1284
+ def initialize ( entities , api_only , shallow , ** options )
1289
1285
super
1290
1286
@as = nil
1291
1287
@controller = ( options [ :controller ] || plural ) . to_s
@@ -1350,19 +1346,17 @@ def resources_path_names(options)
1350
1346
#
1351
1347
# ### Options
1352
1348
# Takes same options as [resources](rdoc-ref:#resources)
1353
- def resource ( *resources , &block )
1354
- options = resources . extract_options! . dup
1355
-
1356
- if apply_common_behavior_for ( :resource , resources , options , &block )
1349
+ def resource ( *resources , concerns : nil , **options , &block )
1350
+ if apply_common_behavior_for ( :resource , resources , concerns :, **options , &block )
1357
1351
return self
1358
1352
end
1359
1353
1360
1354
with_scope_level ( :resource ) do
1361
1355
options = apply_action_options options
1362
- resource_scope ( SingletonResource . new ( resources . pop , api_only? , @scope [ :shallow ] , options ) ) do
1356
+ resource_scope ( SingletonResource . new ( resources . pop , api_only? , @scope [ :shallow ] , ** options ) ) do
1363
1357
yield if block_given?
1364
1358
1365
- concerns ( options [ : concerns] ) if options [ : concerns]
1359
+ concerns ( * concerns ) if concerns
1366
1360
1367
1361
new do
1368
1362
get :new
@@ -1520,19 +1514,17 @@ def resource(*resources, &block)
1520
1514
#
1521
1515
# # resource actions are at /admin/posts.
1522
1516
# resources :posts, path: "admin/posts"
1523
- def resources ( *resources , &block )
1524
- options = resources . extract_options! . dup
1525
-
1526
- if apply_common_behavior_for ( :resources , resources , options , &block )
1517
+ def resources ( *resources , concerns : nil , **options , &block )
1518
+ if apply_common_behavior_for ( :resources , resources , concerns :, **options , &block )
1527
1519
return self
1528
1520
end
1529
1521
1530
1522
with_scope_level ( :resources ) do
1531
1523
options = apply_action_options options
1532
- resource_scope ( Resource . new ( resources . pop , api_only? , @scope [ :shallow ] , options ) ) do
1524
+ resource_scope ( Resource . new ( resources . pop , api_only? , @scope [ :shallow ] , ** options ) ) do
1533
1525
yield if block_given?
1534
1526
1535
- concerns ( options [ : concerns] ) if options [ : concerns]
1527
+ concerns ( * concerns ) if concerns
1536
1528
1537
1529
collection do
1538
1530
get :index if parent_resource . actions . include? ( :index )
@@ -1617,19 +1609,19 @@ def nested(&block)
1617
1609
if shallow? && shallow_nesting_depth >= 1
1618
1610
shallow_scope do
1619
1611
path_scope ( parent_resource . nested_scope ) do
1620
- scope ( nested_options , &block )
1612
+ scope ( ** nested_options , &block )
1621
1613
end
1622
1614
end
1623
1615
else
1624
1616
path_scope ( parent_resource . nested_scope ) do
1625
- scope ( nested_options , &block )
1617
+ scope ( ** nested_options , &block )
1626
1618
end
1627
1619
end
1628
1620
end
1629
1621
end
1630
1622
1631
1623
# See ActionDispatch::Routing::Mapper::Scoping#namespace.
1632
- def namespace ( path , options = { } )
1624
+ def namespace ( name , as : DEFAULT , path : DEFAULT , shallow_path : DEFAULT , shallow_prefix : DEFAULT , ** options , & block )
1633
1625
if resource_scope?
1634
1626
nested { super }
1635
1627
else
@@ -1784,22 +1776,21 @@ def parent_resource
1784
1776
@scope [ :scope_level_resource ]
1785
1777
end
1786
1778
1787
- def apply_common_behavior_for ( method , resources , options , &block )
1779
+ def apply_common_behavior_for ( method , resources , shallow : nil , ** options , &block )
1788
1780
if resources . length > 1
1789
- resources . each { |r | public_send ( method , r , options , &block ) }
1781
+ resources . each { |r | public_send ( method , r , shallow : , ** options , &block ) }
1790
1782
return true
1791
1783
end
1792
1784
1793
- if options [ :shallow ]
1794
- options . delete ( :shallow )
1795
- shallow do
1796
- public_send ( method , resources . pop , options , &block )
1785
+ if shallow
1786
+ self . shallow do
1787
+ public_send ( method , resources . pop , **options , &block )
1797
1788
end
1798
1789
return true
1799
1790
end
1800
1791
1801
1792
if resource_scope?
1802
- nested { public_send ( method , resources . pop , options , &block ) }
1793
+ nested { public_send ( method , resources . pop , shallow : , ** options , &block ) }
1803
1794
return true
1804
1795
end
1805
1796
@@ -1808,9 +1799,9 @@ def apply_common_behavior_for(method, resources, options, &block)
1808
1799
end
1809
1800
1810
1801
scope_options = options . slice! ( *RESOURCE_OPTIONS )
1811
- unless scope_options . empty?
1812
- scope ( scope_options ) do
1813
- public_send ( method , resources . pop , options , &block )
1802
+ if ! scope_options . empty? || ! shallow . nil ?
1803
+ scope ( ** scope_options , shallow : ) do
1804
+ public_send ( method , resources . pop , ** options , &block )
1814
1805
end
1815
1806
return true
1816
1807
end
@@ -1886,9 +1877,10 @@ def canonical_action?(action)
1886
1877
end
1887
1878
1888
1879
def shallow_scope
1889
- scope = { as : @scope [ :shallow_prefix ] ,
1890
- path : @scope [ :shallow_path ] }
1891
- @scope = @scope . new scope
1880
+ @scope = @scope . new (
1881
+ as : @scope [ :shallow_prefix ] ,
1882
+ path : @scope [ :shallow_path ] ,
1883
+ )
1892
1884
1893
1885
yield
1894
1886
ensure
@@ -2152,8 +2144,7 @@ def concern(name, callable = nil, &block)
2152
2144
# namespace :posts do
2153
2145
# concerns :commentable
2154
2146
# end
2155
- def concerns ( *args )
2156
- options = args . extract_options!
2147
+ def concerns ( *args , **options )
2157
2148
args . flatten . each do |name |
2158
2149
if concern = @concerns [ name ]
2159
2150
concern . call ( self , options )
0 commit comments