123456789_123456789_123456789_123456789_123456789_

Class: ActionController::MimeResponds::Collector::VariantCollector

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: actionpack/lib/action_controller/metal/mime_responds.rb

Class Method Summary

Instance Method Summary

Constructor Details

.new(variant = nil) ⇒ VariantCollector

[ GitHub ]

  
# File 'actionpack/lib/action_controller/metal/mime_responds.rb', line 302

def initialize(variant = nil)
  @variant = variant
  @variants = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, &block)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/metal/mime_responds.rb', line 318

def method_missing(name, *, &block)
  @variants[name] = block if block_given?
end

Instance Method Details

#all(*args, &block)

Alias for #any.

[ GitHub ]

  
# File 'actionpack/lib/action_controller/metal/mime_responds.rb', line 316

alias :all :any

#any(*args, &block) Also known as: #all

[ GitHub ]

  
# File 'actionpack/lib/action_controller/metal/mime_responds.rb', line 307

def any(*args, &block)
  if block_given?
    if args.any? && args.none? { |a| a == @variant }
      args.each { |v| @variants[v] = block }
    else
      @variants[:any] = block
    end
  end
end

#variant

[ GitHub ]

  
# File 'actionpack/lib/action_controller/metal/mime_responds.rb', line 322

def variant
  if @variant.empty?
    @variants[:none] || @variants[:any]
  else
    @variants[variant_key]
  end
end

#variant_key (private)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/metal/mime_responds.rb', line 331

def variant_key
  @variant.find { |variant| @variants.key?(variant) } || :any
end