Sha256: b6e47956e4c79e46471cfa582d1fc0fe493d2fd86cb2bcbe375c7335079937f6

Contents?: true

Size: 1.35 KB

Versions: 6

Compression:

Stored size: 1.35 KB

Contents

module Spree
  module SendWithUsMailer
    class Base
      class_attribute :defaults
      class_attribute :default_url_options

      self.defaults = {}.freeze

      class << self
        def default(value = nil)
          self.defaults = defaults.merge(value).freeze if value
          defaults
        end

        def mailer_methods
          methods = public_instance_methods - superclass.public_instance_methods

          # Reject route helper methods.
          methods.reject{ |m| m.to_s.end_with?("_url", "_path") }
        end

        def method_missing(method_name, *args)
          if mailer_methods.include?(method_name.to_sym)
            new(method_name, *args).message
          else
            super(method_name, *args)
          end
        end

        def respond_to?(symbol, include_private = false)
          super || mailer_methods.include?(symbol)
        end
      end

      attr_reader :message
      attr_reader :action

      def initialize(method_name, *args)
        @message = Spree::SendWithUs::Message.new
        @action = method_name
        self.send(method_name, *args)
      end

      def mail(params = {})
        @message.merge!(self.class.defaults.merge(params))
      end

      def assign(key, value)
        @message.assign(key, value)
      end

      ActiveSupport.run_load_hooks(:spree_sendwithus_mailer, self)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
spree_sendwithus-2.0.11.8 lib/spree_sendwithus/mailer.rb
spree_sendwithus-2.0.11.7 lib/spree_sendwithus/mailer.rb
spree_sendwithus-2.0.11.6 lib/spree_sendwithus/mailer.rb
spree_sendwithus-2.0.11.5 lib/spree_sendwithus/mailer.rb
spree_sendwithus-2.0.11.4 lib/spree_sendwithus/mailer.rb
spree_sendwithus-2.0.11.3 lib/spree_sendwithus/mailer.rb