Class: ActionController::MimeResponds::Collector

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

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AbstractController::Collector

generate_method_for_mime

Constructor Details

#initialize(mimes, &block) ⇒ Collector

Returns a new instance of Collector.



285
286
287
288
# File 'actionpack/lib/action_controller/metal/mime_responds.rb', line 285

def initialize(mimes, &block)
  @order, @responses, @default_response = [], {}, block
  mimes.each { |mime| send(mime) }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class AbstractController::Collector

Instance Attribute Details

#orderObject

Returns the value of attribute order



283
284
285
# File 'actionpack/lib/action_controller/metal/mime_responds.rb', line 283

def order
  @order
end

Instance Method Details

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



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

def any(*args, &block)
  if args.any?
    args.each { |type| send(type, &block) }
  else
    custom(Mime::ALL, &block)
  end
end

#custom(mime_type, &block) ⇒ Object



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

def custom(mime_type, &block)
  mime_type = Mime::Type.lookup(mime_type.to_s) unless mime_type.is_a?(Mime::Type)
  @order << mime_type
  @responses[mime_type] ||= block
end

#response_for(mime) ⇒ Object



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

def response_for(mime)
  @responses[mime] || @responses[Mime::ALL] || @default_response
end