Class: ActionController::MimeResponds::Collector::VariantCollector
- Inherits:
-
Object
- Object
- ActionController::MimeResponds::Collector::VariantCollector
- Defined in:
- 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, *args, &block) ⇒ Object
- #variant ⇒ Object
Constructor Details
#initialize(variant = nil) ⇒ VariantCollector
Returns a new instance of VariantCollector.
513 514 515 516 |
# File 'lib/action_controller/metal/mime_responds.rb', line 513 def initialize(variant = nil) @variant = variant @variants = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
529 530 531 |
# File 'lib/action_controller/metal/mime_responds.rb', line 529 def method_missing(name, *args, &block) @variants[name] = block if block_given? end |
Instance Method Details
#any(*args, &block) ⇒ Object Also known as: all
518 519 520 521 522 523 524 525 526 |
# File 'lib/action_controller/metal/mime_responds.rb', line 518 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
533 534 535 536 537 538 539 540 541 542 543 |
# File 'lib/action_controller/metal/mime_responds.rb', line 533 def variant if @variant.nil? @variants[:none] || @variants[:any] elsif (@variants.keys & @variant).any? @variant.each do |v| return @variants[v] if @variants.key?(v) end else @variants[:any] end end |