Class: ActionController::MimeResponds::Collector::VariantCollector
- Inherits:
-
Object
- Object
- ActionController::MimeResponds::Collector::VariantCollector
show all
- Defined in:
- lib/action_controller/metal/mime_responds.rb
Overview
Instance Method Summary
collapse
Constructor Details
290
291
292
293
|
# File 'lib/action_controller/metal/mime_responds.rb', line 290
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
306
307
308
|
# File 'lib/action_controller/metal/mime_responds.rb', line 306
def method_missing(name, *args, &block)
@variants[name] = block if block_given?
end
|
Instance Method Details
#any(*args, &block) ⇒ Object
Also known as:
all
295
296
297
298
299
300
301
302
303
|
# File 'lib/action_controller/metal/mime_responds.rb', line 295
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
310
311
312
313
314
315
316
317
318
319
320
|
# File 'lib/action_controller/metal/mime_responds.rb', line 310
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
|