Sha256: e2d214ee50201497018bb17fff1743216ea6e334cb340f55e8c97b2f4fe870c4

Contents?: true

Size: 901 Bytes

Versions: 2

Compression:

Stored size: 901 Bytes

Contents

# -*- coding: utf-8 -*-

# Подключается через `has_courier` дает модели метод `message(key, options)`. Пример вызова:
#
# @@@
# user.message :comments_in_my_plan, :comments=>@comments, :level=>:success
# @@@


module Courier::Owner
  def has_courier
    has_one :courier, :as => :owner, :dependent => :destroy, :class_name=>'Courier::OwnerSetting'
    has_many :courier_messages, :as => :owner, :dependent => :destroy, :class_name=>'Courier::Message'
    include InstanceMethods

    after_create do
      create_courier
    end
  end

  module InstanceMethods
    def message(template_key, args={})
      template = Courier.template(template_key)
      Courier.config.services_order.select do |service|
        create_courier unless courier
        courier.on?(template, service, args) and service.message(self, template, args)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
courier-0.2.4 lib/courier/owner.rb
courier-0.2.3 lib/courier/owner.rb