diff options
author | Piotr Sarnacki <drogus@gmail.com> | 2010-09-01 19:17:47 +0200 |
---|---|---|
committer | Piotr Sarnacki <drogus@gmail.com> | 2010-09-03 22:59:15 +0200 |
commit | b8d6dc3c84321c751ab2ca8232e1e3fb332a844c (patch) | |
tree | 0e6dee18bab820dcbdfd37518a81eb81447b45e6 /actionpack/lib | |
parent | b43b686b022c4253a4a6f6f1b663b99d7a9adf4f (diff) | |
download | rails-b8d6dc3c84321c751ab2ca8232e1e3fb332a844c.tar.gz rails-b8d6dc3c84321c751ab2ca8232e1e3fb332a844c.tar.bz2 rails-b8d6dc3c84321c751ab2ca8232e1e3fb332a844c.zip |
Implemented RouteSet#default_scope, which allows to set the scope for the entire routes object
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_dispatch/routing/mapper.rb | 6 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/routing/route_set.rb | 8 |
2 files changed, 12 insertions, 2 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index b437d7a17d..900900ee24 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -274,6 +274,12 @@ module ActionDispatch end alias_method :default_url_options, :default_url_options= + def with_default_scope(scope, &block) + scope(scope) do + instance_exec(&block) + end + end + private def app_name(app) return unless app.respond_to?(:routes) diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 0d83ca956b..107e44287d 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -199,7 +199,7 @@ module ActionDispatch end end - attr_accessor :set, :routes, :named_routes + attr_accessor :set, :routes, :named_routes, :default_scope attr_accessor :disable_clear_and_finalize, :resources_path_names attr_accessor :default_url_options, :request_class, :valid_conditions @@ -230,7 +230,11 @@ module ActionDispatch if block.arity == 1 mapper.instance_exec(DeprecatedMapper.new(self), &block) else - mapper.instance_exec(&block) + if default_scope + mapper.with_default_scope(default_scope, &block) + else + mapper.instance_exec(&block) + end end finalize! unless @disable_clear_and_finalize |