@@ -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
@@ -872,8 +872,7 @@ module Scoping
872
872
# scope as: "sekret" do
873
873
# resources :posts
874
874
# end
875
- def scope ( *args )
876
- options = args . extract_options! . dup
875
+ def scope ( *args , only : nil , except : nil , **options )
877
876
scope = { }
878
877
879
878
options [ :path ] = args . flatten . join ( "/" ) if args . any?
@@ -894,9 +893,8 @@ def scope(*args)
894
893
block , options [ :constraints ] = options [ :constraints ] , { }
895
894
end
896
895
897
- if options . key? ( :only ) || options . key? ( :except )
898
- scope [ :action_options ] = { only : options . delete ( :only ) ,
899
- except : options . delete ( :except ) }
896
+ if only || except
897
+ scope [ :action_options ] = { only :, except : }
900
898
end
901
899
902
900
if options . key? :anchor
@@ -976,18 +974,16 @@ def controller(controller)
976
974
# namespace :admin, as: "sekret" do
977
975
# resources :posts
978
976
# end
979
- def namespace ( path , options = { } , &block )
980
- path = path . to_s
981
-
982
- defaults = {
983
- module : path ,
984
- as : options . fetch ( :as , path ) ,
985
- shallow_path : options . fetch ( :path , path ) ,
986
- shallow_prefix : options . fetch ( :as , path )
987
- }
977
+ def namespace ( name , as : DEFAULT , path : DEFAULT , shallow_path : DEFAULT , shallow_prefix : DEFAULT , **options , &block )
978
+ name = name . to_s
979
+ options [ :module ] ||= name
980
+ as = name if as == DEFAULT
981
+ path = name if path == DEFAULT
982
+ shallow_path = path if shallow_path == DEFAULT
983
+ shallow_prefix = as if shallow_prefix == DEFAULT
988
984
989
- path_scope ( options . delete ( : path) { path } ) do
990
- scope ( defaults . merge! ( options ) , &block )
985
+ path_scope ( path ) do
986
+ scope ( ** options , as : , shallow_path : , shallow_prefix : , &block )
991
987
end
992
988
end
993
989
@@ -1181,7 +1177,7 @@ module Resources
1181
1177
class Resource # :nodoc:
1182
1178
attr_reader :controller , :path , :param
1183
1179
1184
- def initialize ( entities , api_only , shallow , options = { } )
1180
+ def initialize ( entities , api_only , shallow , only : nil , except : nil , ** options )
1185
1181
if options [ :param ] . to_s . include? ( ":" )
1186
1182
raise ArgumentError , ":param option can't contain colons"
1187
1183
end
@@ -1194,8 +1190,8 @@ def initialize(entities, api_only, shallow, options = {})
1194
1190
@options = options
1195
1191
@shallow = shallow
1196
1192
@api_only = api_only
1197
- @only = options . delete : only
1198
- @except = options . delete : except
1193
+ @only = only
1194
+ @except = except
1199
1195
end
1200
1196
1201
1197
def default_actions
@@ -1274,7 +1270,7 @@ def singleton?; false; end
1274
1270
end
1275
1271
1276
1272
class SingletonResource < Resource # :nodoc:
1277
- def initialize ( entities , api_only , shallow , options )
1273
+ def initialize ( entities , api_only , shallow , ** options )
1278
1274
super
1279
1275
@as = nil
1280
1276
@controller = ( options [ :controller ] || plural ) . to_s
@@ -1339,19 +1335,17 @@ def resources_path_names(options)
1339
1335
#
1340
1336
# ### Options
1341
1337
# Takes same options as [resources](rdoc-ref:#resources)
1342
- def resource ( *resources , &block )
1343
- options = resources . extract_options! . dup
1344
-
1345
- if apply_common_behavior_for ( :resource , resources , options , &block )
1338
+ def resource ( *resources , concerns : nil , **options , &block )
1339
+ if apply_common_behavior_for ( :resource , resources , concerns :, **options , &block )
1346
1340
return self
1347
1341
end
1348
1342
1349
1343
with_scope_level ( :resource ) do
1350
1344
options = apply_action_options options
1351
- resource_scope ( SingletonResource . new ( resources . pop , api_only? , @scope [ :shallow ] , options ) ) do
1345
+ resource_scope ( SingletonResource . new ( resources . pop , api_only? , @scope [ :shallow ] , ** options ) ) do
1352
1346
yield if block_given?
1353
1347
1354
- concerns ( options [ : concerns] ) if options [ : concerns]
1348
+ concerns ( * concerns ) if concerns
1355
1349
1356
1350
new do
1357
1351
get :new
@@ -1509,19 +1503,17 @@ def resource(*resources, &block)
1509
1503
#
1510
1504
# # resource actions are at /admin/posts.
1511
1505
# resources :posts, path: "admin/posts"
1512
- def resources ( *resources , &block )
1513
- options = resources . extract_options! . dup
1514
-
1515
- if apply_common_behavior_for ( :resources , resources , options , &block )
1506
+ def resources ( *resources , concerns : nil , **options , &block )
1507
+ if apply_common_behavior_for ( :resources , resources , concerns :, **options , &block )
1516
1508
return self
1517
1509
end
1518
1510
1519
1511
with_scope_level ( :resources ) do
1520
1512
options = apply_action_options options
1521
- resource_scope ( Resource . new ( resources . pop , api_only? , @scope [ :shallow ] , options ) ) do
1513
+ resource_scope ( Resource . new ( resources . pop , api_only? , @scope [ :shallow ] , ** options ) ) do
1522
1514
yield if block_given?
1523
1515
1524
- concerns ( options [ : concerns] ) if options [ : concerns]
1516
+ concerns ( * concerns ) if concerns
1525
1517
1526
1518
collection do
1527
1519
get :index if parent_resource . actions . include? ( :index )
@@ -1606,19 +1598,19 @@ def nested(&block)
1606
1598
if shallow? && shallow_nesting_depth >= 1
1607
1599
shallow_scope do
1608
1600
path_scope ( parent_resource . nested_scope ) do
1609
- scope ( nested_options , &block )
1601
+ scope ( ** nested_options , &block )
1610
1602
end
1611
1603
end
1612
1604
else
1613
1605
path_scope ( parent_resource . nested_scope ) do
1614
- scope ( nested_options , &block )
1606
+ scope ( ** nested_options , &block )
1615
1607
end
1616
1608
end
1617
1609
end
1618
1610
end
1619
1611
1620
1612
# See ActionDispatch::Routing::Mapper::Scoping#namespace.
1621
- def namespace ( path , options = { } )
1613
+ def namespace ( name , as : DEFAULT , path : DEFAULT , shallow_path : DEFAULT , shallow_prefix : DEFAULT , ** options , & block )
1622
1614
if resource_scope?
1623
1615
nested { super }
1624
1616
else
@@ -1773,22 +1765,21 @@ def parent_resource
1773
1765
@scope [ :scope_level_resource ]
1774
1766
end
1775
1767
1776
- def apply_common_behavior_for ( method , resources , options , &block )
1768
+ def apply_common_behavior_for ( method , resources , shallow : nil , ** options , &block )
1777
1769
if resources . length > 1
1778
- resources . each { |r | public_send ( method , r , options , &block ) }
1770
+ resources . each { |r | public_send ( method , r , shallow : , ** options , &block ) }
1779
1771
return true
1780
1772
end
1781
1773
1782
- if options [ :shallow ]
1783
- options . delete ( :shallow )
1784
- shallow do
1785
- public_send ( method , resources . pop , options , &block )
1774
+ if shallow
1775
+ self . shallow do
1776
+ public_send ( method , resources . pop , **options , &block )
1786
1777
end
1787
1778
return true
1788
1779
end
1789
1780
1790
1781
if resource_scope?
1791
- nested { public_send ( method , resources . pop , options , &block ) }
1782
+ nested { public_send ( method , resources . pop , shallow : , ** options , &block ) }
1792
1783
return true
1793
1784
end
1794
1785
@@ -1797,9 +1788,9 @@ def apply_common_behavior_for(method, resources, options, &block)
1797
1788
end
1798
1789
1799
1790
scope_options = options . slice! ( *RESOURCE_OPTIONS )
1800
- unless scope_options . empty?
1801
- scope ( scope_options ) do
1802
- public_send ( method , resources . pop , options , &block )
1791
+ if ! scope_options . empty? || ! shallow . nil ?
1792
+ scope ( ** scope_options , shallow : ) do
1793
+ public_send ( method , resources . pop , ** options , &block )
1803
1794
end
1804
1795
return true
1805
1796
end
@@ -1875,9 +1866,10 @@ def canonical_action?(action)
1875
1866
end
1876
1867
1877
1868
def shallow_scope
1878
- scope = { as : @scope [ :shallow_prefix ] ,
1879
- path : @scope [ :shallow_path ] }
1880
- @scope = @scope . new scope
1869
+ @scope = @scope . new (
1870
+ as : @scope [ :shallow_prefix ] ,
1871
+ path : @scope [ :shallow_path ] ,
1872
+ )
1881
1873
1882
1874
yield
1883
1875
ensure
@@ -2141,8 +2133,7 @@ def concern(name, callable = nil, &block)
2141
2133
# namespace :posts do
2142
2134
# concerns :commentable
2143
2135
# end
2144
- def concerns ( *args )
2145
- options = args . extract_options!
2136
+ def concerns ( *args , **options )
2146
2137
args . flatten . each do |name |
2147
2138
if concern = @concerns [ name ]
2148
2139
concern . call ( self , options )
0 commit comments