Sha256: 4f730a7b23d770ee9fdf81fa5a363f007a7b7e66f2aaa8285cfab68fc9cebaa2

Contents?: true

Size: 1.05 KB

Versions: 2

Compression:

Stored size: 1.05 KB

Contents

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


# # Courier::Sender (extenstion для AR-модели пользователя-отправителя)

# Подключается через `acts_as_sender` дает модели метод `message(key, options)`. Пример вызова:

# @@@
# user.notify :comments_in_my_plan, :comments=>@comments, :level=>:success
# user.notify_failure :cant_import_plans, :provider=>:facebook
# @@@


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.1 lib/courier/owner.rb
courier-0.2.0 lib/courier/owner.rb