diff options
Diffstat (limited to 'actionmailer/lib/action_mailer/collector.rb')
-rw-r--r-- | actionmailer/lib/action_mailer/collector.rb | 32 |
1 files changed, 32 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..888410fa75 --- /dev/null +++ b/actionmailer/lib/action_mailer/collector.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +require "abstract_controller/collector" +require "active_support/core_ext/hash/reverse_merge" +require "active_support/core_ext/array/extract_options" + +module ActionMailer + class Collector + include AbstractController::Collector + attr_reader :responses + + def initialize(context, &block) + @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) } + end + alias :all :any + + 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 + @responses << options + end + end +end |