Sha256: 1145df44c6a00f3744af5a85f333ca45ec0c067b5a75d0c448d4e0958dba8e69

Contents?: true

Size: 577 Bytes

Versions: 1

Compression:

Stored size: 577 Bytes

Contents

module OrderReporting
  class Report
    def initialize(name)
      @name = name
    end

    def send_report
      orders.tap do |orders|
        deliver(mailer.send(@name, orders))
      end
    end

    private

    def deliver(mail)
      if mail.respond_to?(:deliver)
        mail.deliver
      elsif mail.respond_to?(:deliver_now)
        mail.deliver_now
      end
    end

    def mailer
      report[:mailer_class] || OrderReporting.mailer_class
    end

    def orders
      report[:query].orders
    end

    def report
      OrderReporting[@name]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
spree_order_reporting-0.0.2 lib/order_reporting/report.rb