collector.rb 852 B

123456789101112131415161718192021222324252627282930
  1. require 'abstract_controller/collector'
  2. require 'active_support/core_ext/hash/reverse_merge'
  3. require 'active_support/core_ext/array/extract_options'
  4. module ActionMailer #:nodoc:
  5. class Collector
  6. include AbstractController::Collector
  7. attr_reader :responses
  8. def initialize(context, &block)
  9. @context = context
  10. @responses = []
  11. @default_render = block
  12. end
  13. def any(*args, &block)
  14. options = args.extract_options!
  15. raise "You have to supply at least one format" if args.empty?
  16. args.each { |type| send(type, options.dup, &block) }
  17. end
  18. alias :all :any
  19. def custom(mime, options={})
  20. options.reverse_merge!(:content_type => mime.to_s)
  21. @context.formats = [mime.to_sym]
  22. options[:body] = block_given? ? yield : @default_render.call
  23. @responses << options
  24. end
  25. end
  26. end