Class: ActionController::MimeResponds::Collector

Inherits:
Object
  • Object
show all
Includes:
AbstractController::Collector
Defined in:
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(&block) ⇒ Collector

Returns a new instance of Collector.


280
281
282
# File 'lib/action_controller/metal/mime_responds.rb', line 280

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


278
279
280
# File 'lib/action_controller/metal/mime_responds.rb', line 278

def order
  @order
end

Instance Method Details

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


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

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


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

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

#response_for(mime) ⇒ Object


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

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