Module: ActionDispatch::Routing::Mapper::Scoping
- Included in:
- ActionDispatch::Routing::Mapper
- Defined in:
- lib/action_dispatch/routing/mapper.rb
Instance Method Summary collapse
- #constraints(constraints = {}) ⇒ Object
- #controller(controller, options = {}) ⇒ Object
- #defaults(defaults = {}) ⇒ Object
-
#initialize(*args) ⇒ Object
:nodoc:.
- #namespace(path, options = {}) ⇒ Object
- #scope(*args) ⇒ Object
Instance Method Details
#constraints(constraints = {}) ⇒ Object
376 377 378 |
# File 'lib/action_dispatch/routing/mapper.rb', line 376 def constraints(constraints = {}) scope(:constraints => constraints) { yield } end |
#controller(controller, options = {}) ⇒ Object
364 365 366 367 |
# File 'lib/action_dispatch/routing/mapper.rb', line 364 def controller(controller, ={}) [:controller] = controller scope() { yield } end |
#defaults(defaults = {}) ⇒ Object
380 381 382 |
# File 'lib/action_dispatch/routing/mapper.rb', line 380 def defaults(defaults = {}) scope(:defaults => defaults) { yield } end |
#initialize(*args) ⇒ Object
:nodoc:
318 319 320 321 |
# File 'lib/action_dispatch/routing/mapper.rb', line 318 def initialize(*args) #:nodoc: @scope = {} super end |
#namespace(path, options = {}) ⇒ Object
369 370 371 372 373 374 |
# File 'lib/action_dispatch/routing/mapper.rb', line 369 def namespace(path, = {}) path = path.to_s = { :path => path, :as => path, :module => path, :shallow_path => path, :shallow_prefix => path }.merge!() scope() { yield } end |
#scope(*args) ⇒ Object
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 |
# File 'lib/action_dispatch/routing/mapper.rb', line 323 def scope(*args) = args. = .dup if name_prefix = .delete(:name_prefix) [:as] ||= name_prefix ActiveSupport::Deprecation.warn ":name_prefix was deprecated in the new router syntax. Use :as instead.", caller end [:path] = args.first if args.first.is_a?(String) recover = {} [:constraints] ||= {} unless [:constraints].is_a?(Hash) block, [:constraints] = [:constraints], {} end .each do |option| if value = .delete(option) recover[option] = @scope[option] @scope[option] = send("merge_#{option}_scope", @scope[option], value) end end recover[:block] = @scope[:blocks] @scope[:blocks] = merge_blocks_scope(@scope[:blocks], block) recover[:options] = @scope[:options] @scope[:options] = (@scope[:options], ) yield self ensure .each do |option| @scope[option] = recover[option] if recover.has_key?(option) end @scope[:options] = recover[:options] @scope[:blocks] = recover[:block] end |