Sha256: 17771045ab3272491427b3d32f6bb254a3331203012e5dee838ee3fd9a859ed8

Contents?: true

Size: 884 Bytes

Versions: 2

Compression:

Stored size: 884 Bytes

Contents

module PubsubNotifier
  module ActsAsNotifier
    def self.included(klass)
      klass.extend ClassMethods
    end

    module ClassMethods
      # Override ActionMailer::Base.method_missing
      # https://github.com/rails/rails/blob/master/actionmailer/lib/action_mailer/base.rb#L576
      def acts_as_notifier
        class_eval do
          class << self
            private

              def method_missing(method_name, *args)
                if action_methods.include?(method_name.to_s)
                  ::ActionMailer::MessageDelivery.new(self, method_name, *args).tap(&:deliver)
                else
                  super
                end
              end

              def respond_to_missing?(method_name, include_all = false)
                action_methods.include?(method_name.to_s) || super
              end
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pubsub_notifier-0.1.2 lib/pubsub_notifier/acts_as_notifier.rb
pubsub_notifier-0.1.1 lib/pubsub_notifier/acts_as_notifier.rb