Module: ResourcesController::ClassMethods

Defined in:
lib/resources_controller.rb

Instance Method Summary collapse

Instance Method Details

#nested_in(*names, &block) ⇒ Object

Specifies that this controller has a particular enclosing resource.

This can be called with an array of symbols (in which case options can’t be specified) or a symbol with options.

See Specification#new for details of how to call this.

Raises:

  • (ArgumentError)


524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
# File 'lib/resources_controller.rb', line 524

def nested_in(*names, &block)
  options = names.extract_options!
  raise ArgumentError, "when giving more than one nesting, you may not specify options or a block" if names.length > 1 and (block_given? or options.length > 0)
  
  # convert :polymorphic option to '?'
  if options.delete(:polymorphic)
    raise ArgumentError, "when specifying :polymorphic => true, no block or other options may be given" if block_given? or options.length > 0
    names = ["?#{names.first}"] 
  end

  # ignore first '*' if it has already been specified by :load_enclosing == true
  names.shift if specifications == ['*'] && names.first == '*'
  
  names.each do |name|
    ensure_sane_wildcard if name == '*'
    specifications << (name.to_s =~ /^(\*|\?(.*))$/ ? name.to_s : Specification.new(name, options, &block))
  end
end