Module: ActionDispatch::Routing::Mapper::Scoping

Included in:
ActionDispatch::Routing::Mapper
Defined in:
lib/action_dispatch/routing/mapper.rb

Instance Method Summary collapse

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, options={})
  options[:controller] = controller
  scope(options) { 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, options = {})
  path = path.to_s
  options = { :path => path, :as => path, :module => path,
              :shallow_path => path, :shallow_prefix => path }.merge!(options)
  scope(options) { 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)
  options = args.extract_options!
  options = options.dup

  if name_prefix = options.delete(:name_prefix)
    options[:as] ||= name_prefix
    ActiveSupport::Deprecation.warn ":name_prefix was deprecated in the new router syntax. Use :as instead.", caller
  end

  options[:path] = args.first if args.first.is_a?(String)
  recover = {}

  options[:constraints] ||= {}
  unless options[:constraints].is_a?(Hash)
    block, options[:constraints] = options[:constraints], {}
  end

  scope_options.each do |option|
    if value = options.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]  = merge_options_scope(@scope[:options], options)

  yield
  self
ensure
  scope_options.each do |option|
    @scope[option] = recover[option] if recover.has_key?(option)
  end

  @scope[:options] = recover[:options]
  @scope[:blocks]  = recover[:block]
end