module ActionDispatch::Routing::Mapper::Scoping

def constraints(constraints = {})

def constraints(constraints = {})
  scope(:constraints => constraints) { yield }
end

def controller(controller, options={})

def controller(controller, options={})
  options[:controller] = controller
  scope(options) { yield }
end

def defaults(defaults = {})

def defaults(defaults = {})
  scope(:defaults => defaults) { yield }
end

def initialize(*args) #:nodoc:

:nodoc:
def initialize(*args) #:nodoc:
  @scope = {}
  super
end

def merge_as_scope(parent, child)

def merge_as_scope(parent, child)
  parent ? "#{parent}_#{child}" : child
end

def merge_blocks_scope(parent, child)

def merge_blocks_scope(parent, child)
  merged = parent ? parent.dup : []
  merged << child if child
  merged
end

def merge_constraints_scope(parent, child)

def merge_constraints_scope(parent, child)
  merge_options_scope(parent, child)
end

def merge_controller_scope(parent, child)

def merge_controller_scope(parent, child)
  child
end

def merge_defaults_scope(parent, child)

def merge_defaults_scope(parent, child)
  merge_options_scope(parent, child)
end

def merge_module_scope(parent, child)

def merge_module_scope(parent, child)
  parent ? "#{parent}/#{child}" : child
end

def merge_options_scope(parent, child)

def merge_options_scope(parent, child)
  (parent || {}).except(*override_keys(child)).merge(child)
end

def merge_path_names_scope(parent, child)

def merge_path_names_scope(parent, child)
  merge_options_scope(parent, child)
end

def merge_path_scope(parent, child)

def merge_path_scope(parent, child)
  Mapper.normalize_path("#{parent}/#{child}")
end

def merge_shallow_path_scope(parent, child)

def merge_shallow_path_scope(parent, child)
  Mapper.normalize_path("#{parent}/#{child}")
end

def merge_shallow_prefix_scope(parent, child)

def merge_shallow_prefix_scope(parent, child)
  parent ? "#{parent}_#{child}" : child
end

def merge_shallow_scope(parent, child)

def merge_shallow_scope(parent, child)
  child ? true : false
end

def namespace(path, options = {})

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

def override_keys(child)

def override_keys(child)
  child.key?(:only) || child.key?(:except) ? [:only, :except] : []
end

def scope(*args)

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

def scope_options

def scope_options
  @scope_options ||= private_methods.grep(/^merge_(.+)_scope$/) { $1.to_sym }
end