0003-Optional-Ensure-that-ActiveRecord-Base-objects-are-f.patch

Holger Just, 2017-08-30 12:46

Download (1.88 KB)

View differences:

app/models/mailer.rb
106 106
          "method*, or 3. use a custom Active Job instead of #deliver_later."
107 107
      else
108 108
        args = 'Mailer', @action.to_s, delivery_method.to_s, *@args
109
        ::ActionMailer::DeliveryJob.set(options).perform_later(*args)
109
        DeliveryJob.set(options).perform_later(*args)
110 110
      end
111 111
    end
112 112
  end
113 113

  
114
  class DeliveryJob < ActionMailer::DeliveryJob
115
    module Arguments
116
      extend ActiveJob::Arguments
117
      extend self
118

  
119
      private
120

  
121
      def serialize_argument(argument)
122
        # Ensure that ActiveRecord::Base objects are fully serialized for mail
123
        # sending. This circumvents the globalid gem for this job.
124
        if argument.is_a?(ActiveRecord::Base)
125
          argument.to_yaml
126
        else
127
          super
128
        end
129
      end
130

  
131
      def deserialize_argument(argument)
132
        if argument.is_a?(ActiveRecord::Base)
133
          argument
134
        else
135
          super
136
        end
137
      end
138
    end
139

  
140
    private
141

  
142
    def serialize_arguments(serialized_args)
143
      Arguments.serialize(serialized_args)
144
    end
145

  
146
    def deserialize_arguments(serialized_args)
147
      Arguments.deserialize(serialized_args)
148
    end
149
  end
150

  
114 151
  def process(action, *args)
115 152
    user = args.shift
116 153
    raise ArgumentError, "First argument has to be a user, was #{user.inspect}" unless user.is_a?(User)
117
-