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

Inherits:
Object
  • Object
show all
Defined in:
actionpack/lib/action_controller/metal/mime_responds.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(variant = nil) ⇒ VariantCollector

Returns a new instance of VariantCollector.


276
277
278
279
# File 'actionpack/lib/action_controller/metal/mime_responds.rb', line 276

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


292
293
294
# File 'actionpack/lib/action_controller/metal/mime_responds.rb', line 292

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

Instance Method Details

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


281
282
283
284
285
286
287
288
289
# File 'actionpack/lib/action_controller/metal/mime_responds.rb', line 281

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

#variantObject


296
297
298
299
300
301
302
# File 'actionpack/lib/action_controller/metal/mime_responds.rb', line 296

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