Class: ActionController::MimeResponds::Collector::VariantCollector
- Defined in:
- actionpack/lib/action_controller/metal/mime_responds.rb
Overview
:nodoc:
Instance Method Summary collapse
- #any(*args, &block) ⇒ Object (also: #all)
-
#initialize(variant = nil) ⇒ VariantCollector
constructor
A new instance of VariantCollector.
- #method_missing(name, &block) ⇒ Object
- #variant ⇒ Object
Constructor Details
#initialize(variant = nil) ⇒ VariantCollector
Returns a new instance of VariantCollector.
302 303 304 305 |
# 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) ⇒ Object
318 319 320 |
# 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
#any(*args, &block) ⇒ Object Also known as: all
307 308 309 310 311 312 313 314 315 |
# 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 ⇒ Object
322 323 324 325 326 327 328 |
# 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 |