aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer/lib/action_mailer/collector.rb
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-01-26 01:56:52 +0100
committerJosé Valim <jose.valim@gmail.com>2010-01-26 01:56:52 +0100
commitabad097016bf5243e9812f6a031f421a986b09f7 (patch)
treef526a520a87db9c68ddd3436ce4bdb6f8c3182d1 /actionmailer/lib/action_mailer/collector.rb
parent8974dac92e05dcab8ee552a5f40108c6ac25dc36 (diff)
parentc02391f8f97182e818d22a0f0ec4a5589d2fff15 (diff)
downloadrails-abad097016bf5243e9812f6a031f421a986b09f7.tar.gz
rails-abad097016bf5243e9812f6a031f421a986b09f7.tar.bz2
rails-abad097016bf5243e9812f6a031f421a986b09f7.zip
Merge remote branch 'mikel/master'
Diffstat (limited to 'actionmailer/lib/action_mailer/collector.rb')
-rw-r--r--actionmailer/lib/action_mailer/collector.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/actionmailer/lib/action_mailer/collector.rb b/actionmailer/lib/action_mailer/collector.rb
new file mode 100644
index 0000000000..5431efccfe
--- /dev/null
+++ b/actionmailer/lib/action_mailer/collector.rb
@@ -0,0 +1,36 @@
+require 'abstract_controller/collector'
+require 'active_support/core_ext/hash/reverse_merge'
+require 'active_support/core_ext/array/extract_options'
+
+module ActionMailer #:nodoc:
+ class Collector
+ include AbstractController::Collector
+ attr_reader :responses
+
+ def initialize(context, &block)
+ @context = context
+ @responses = []
+ @default_render = block
+ @default_formats = context.formats
+ 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) }
+ end
+ alias :all :any
+
+ def custom(mime, options={}, &block)
+ options.reverse_merge!(:content_type => mime.to_s)
+ @context.formats = [mime.to_sym]
+ options[:body] = if block
+ block.call
+ else
+ @default_render.call
+ end
+ @responses << options
+ @context.formats = @default_formats
+ end
+ end
+end \ No newline at end of file