2010-01-23 05:50:36 -05:00
|
|
|
require 'abstract_controller/collector'
|
2010-01-23 06:20:20 -05:00
|
|
|
require 'active_support/core_ext/hash/reverse_merge'
|
|
|
|
require 'active_support/core_ext/array/extract_options'
|
2010-01-23 05:50:36 -05:00
|
|
|
|
2012-09-17 20:18:56 -04:00
|
|
|
module ActionMailer
|
2010-01-23 05:50:36 -05:00
|
|
|
class Collector
|
|
|
|
include AbstractController::Collector
|
2010-01-23 06:20:20 -05:00
|
|
|
attr_reader :responses
|
2010-01-23 05:50:36 -05:00
|
|
|
|
2010-01-23 06:20:20 -05:00
|
|
|
def initialize(context, &block)
|
2010-01-23 05:50:36 -05:00
|
|
|
@context = context
|
|
|
|
@responses = []
|
2010-01-23 06:20:20 -05:00
|
|
|
@default_render = block
|
|
|
|
end
|
|
|
|
|
|
|
|
def any(*args, &block)
|
|
|
|
options = args.extract_options!
|
2012-07-05 01:34:31 -04:00
|
|
|
raise ArgumentError, "You have to supply at least one format" if args.empty?
|
2010-01-23 06:46:33 -05:00
|
|
|
args.each { |type| send(type, options.dup, &block) }
|
2010-01-23 05:50:36 -05:00
|
|
|
end
|
2010-01-23 06:20:20 -05:00
|
|
|
alias :all :any
|
2010-01-23 05:50:36 -05:00
|
|
|
|
2013-01-03 16:14:09 -05:00
|
|
|
def custom(mime, options = {})
|
2012-10-07 13:54:14 -04:00
|
|
|
options.reverse_merge!(content_type: mime.to_s)
|
2012-02-21 20:55:56 -05:00
|
|
|
@context.formats = [mime.to_sym]
|
2010-03-19 12:20:15 -04:00
|
|
|
options[:body] = block_given? ? yield : @default_render.call
|
2010-01-23 05:50:36 -05:00
|
|
|
@responses << options
|
|
|
|
end
|
|
|
|
end
|
2012-02-21 20:55:56 -05:00
|
|
|
end
|