~ubuntu-branches/ubuntu/raring/ruby-actionpack-3.2/raring

« back to all changes in this revision

Viewing changes to lib/abstract_controller/collector.rb

  • Committer: Package Import Robot
  • Author(s): Ondřej Surý
  • Date: 2012-04-25 09:14:01 UTC
  • Revision ID: package-import@ubuntu.com-20120425091401-3nkf83btcemhjquo
Tags: upstream-3.2.3
Import upstream version 3.2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require "action_dispatch/http/mime_type"
 
2
 
 
3
module AbstractController
 
4
  module Collector
 
5
    def self.generate_method_for_mime(mime)
 
6
      sym = mime.is_a?(Symbol) ? mime : mime.to_sym
 
7
      const = sym.to_s.upcase
 
8
      class_eval <<-RUBY, __FILE__, __LINE__ + 1
 
9
        def #{sym}(*args, &block)                # def html(*args, &block)
 
10
          custom(Mime::#{const}, *args, &block)  #   custom(Mime::HTML, *args, &block)
 
11
        end                                      # end
 
12
      RUBY
 
13
    end
 
14
 
 
15
    Mime::SET.each do |mime|
 
16
      generate_method_for_mime(mime)
 
17
    end
 
18
 
 
19
  protected
 
20
 
 
21
    def method_missing(symbol, &block)
 
22
      mime_constant = Mime.const_get(symbol.to_s.upcase)
 
23
 
 
24
      if Mime::SET.include?(mime_constant)
 
25
        AbstractController::Collector.generate_method_for_mime(mime_constant)
 
26
        send(symbol, &block)
 
27
      else
 
28
        super
 
29
      end
 
30
    end
 
31
  end
 
32
end
 
 
b'\\ No newline at end of file'