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