1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actionmailer/lib/action_mailer/collector.rb

31 lines
857 B
Ruby
Raw Normal View History

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