rails/actionmailer/lib/action_mailer/collector.rb

30 lines
857 B
Ruby
Raw Normal View History

2010-01-23 10:50:36 +00:00
require 'abstract_controller/collector'
require 'active_support/core_ext/hash/reverse_merge'
require 'active_support/core_ext/array/extract_options'
2010-01-23 10:50:36 +00:00
module ActionMailer #:nodoc:
class Collector
include AbstractController::Collector
attr_reader :responses
2010-01-23 10:50:36 +00:00
def initialize(context, &block)
2010-01-23 10:50:36 +00:00
@context = context
@responses = []
@default_render = block
end
def any(*args, &block)
options = args.extract_options!
raise "You have to supply at least one format" if args.empty?
args.each { |type| send(type, options.dup, &block) }
2010-01-23 10:50:36 +00:00
end
alias :all :any
2010-01-23 10:50:36 +00:00
def custom(mime, options={})
options.reverse_merge!(:content_type => mime.to_s)
@context.freeze_formats([mime.to_sym])
options[:body] = block_given? ? yield : @default_render.call
2010-01-23 10:50:36 +00:00
@responses << options
end
end
end