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) ⇒ Collector

Returns a new instance of Collector


288
289
290
291
# File 'actionpack/lib/action_controller/metal/mime_responds.rb', line 288

def initialize(mimes)
  @order, @responses = [], {}
  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

#formatObject

Returns the value of attribute format


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

def format
  @format
end

#orderObject

Returns the value of attribute order


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

def order
  @order
end

Instance Method Details

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


293
294
295
296
297
298
299
# File 'actionpack/lib/action_controller/metal/mime_responds.rb', line 293

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


302
303
304
305
306
# File 'actionpack/lib/action_controller/metal/mime_responds.rb', line 302

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

#negotiate_format(request) ⇒ Object


312
313
314
# File 'actionpack/lib/action_controller/metal/mime_responds.rb', line 312

def negotiate_format(request)
  @format = request.negotiate_mime(order)
end

#responseObject


308
309
310
# File 'actionpack/lib/action_controller/metal/mime_responds.rb', line 308

def response
  @responses[format] || @responses[Mime::ALL]
end