Module: AbstractController::Collector

Included in:
ActionController::MimeResponds::Collector
Defined in:
lib/abstract_controller/collector.rb

Class Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, &block) ⇒ Object (protected)



25
26
27
28
29
30
31
32
33
34
# File 'lib/abstract_controller/collector.rb', line 25

def method_missing(symbol, &block)
  mime_constant = Mime.const_get(symbol.upcase)

  if Mime::SET.include?(mime_constant)
    AbstractController::Collector.generate_method_for_mime(mime_constant)
    send(symbol, &block)
  else
    super
  end
end

Class Method Details

.generate_method_for_mime(mime) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/abstract_controller/collector.rb', line 5

def self.generate_method_for_mime(mime)
  sym = mime.is_a?(Symbol) ? mime : mime.to_sym
  const = sym.upcase
  class_eval <<-RUBY, __FILE__, __LINE__ + 1
    def #{sym}(*args, &block)                # def html(*args, &block)
      custom(Mime::#{const}, *args, &block)  #   custom(Mime::HTML, *args, &block)
    end                                      # end
  RUBY
end