Class: ActionController::MimeResponds::Collector
- Inherits:
-
Object
- Object
- ActionController::MimeResponds::Collector
show all
- Defined in:
- lib/respond_with_backport.rb
Overview
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(&block) ⇒ Collector
Returns a new instance of Collector.
538
539
540
|
# File 'lib/respond_with_backport.rb', line 538
def initialize(&block)
@order, @responses, @default_response = [], {}, block
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, &block) ⇒ Object
575
576
577
578
579
580
581
582
583
584
|
# File 'lib/respond_with_backport.rb', line 575
def method_missing(symbol, &block)
mime_constant = Mime.const_get(symbol.to_s.upcase)
if Mime::SET.include?(mime_constant)
self.class.generate_method_for_mime(mime_constant)
send(symbol, &block)
else
super
end
end
|
Instance Attribute Details
#order ⇒ Object
Returns the value of attribute order.
536
537
538
|
# File 'lib/respond_with_backport.rb', line 536
def order
@order
end
|
Class Method Details
.generate_method_for_mime(mime) ⇒ Object
561
562
563
564
565
566
567
568
569
|
# File 'lib/respond_with_backport.rb', line 561
def self.generate_method_for_mime(mime)
sym = mime.is_a?(Symbol) ? mime : mime.to_sym
const = sym.to_s.upcase
class_eval " def \#{sym}(&block) # def html(&block)\n custom(Mime::\#{const}, &block) # custom(Mime::HTML, &block)\n end # end\n RUBY\nend\n", __FILE__, __LINE__ + 1
|
Instance Method Details
#any(*args, &block) ⇒ Object
Also known as:
all
542
543
544
545
546
547
548
|
# File 'lib/respond_with_backport.rb', line 542
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
551
552
553
554
555
|
# File 'lib/respond_with_backport.rb', line 551
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
557
558
559
|
# File 'lib/respond_with_backport.rb', line 557
def response_for(mime)
@responses[mime] || @responses[Mime::ALL] || @default_response
end
|