Sha256: 2ed94b5ffa9384e18f52b77d3f544fa6ff7a8cd4893490c14a7b423fb4fa8607

Contents?: true

Size: 1.14 KB

Versions: 4

Compression:

Stored size: 1.14 KB

Contents

# -*- coding: utf-8 -*-
#
# Сообщения от системы пользователю для отображения их через flash. Например:
#
#   :import_contacts - импортированы контакты
#   :import_events - импортированы мероприятия
#
# Сообщения посылаются так:
#
#   user.notice :import_contacts, :provider=>:facebook
#
# Тексты сообщений описываются в локали

class GritterNotice < ActiveRecord::Base
  belongs_to :owner, :polymorphic=>true

  scope :delivered, where("delivered_at is not nul").order('delivered_at')
  scope :fresh, where("delivered_at is null").order('created_at').limit(5)

  serialize :options, Hash

  before_validation :set_options
  validates_presence_of :owner, :text

  def fresh?
    delivered_at.blank?
  end

  def delivered?
    not fresh?
  end

  def destroy_after_deliver?
    true
  end

  def mark_as_delivered
    if destroy_after_deliver?
      destroy
    else
      update_attribute :delivered_at, Time.now
    end
  end

  private

  def set_options
    self.options={} unless self.options
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
gritter_notices-0.4.0 app/models/gritter_notice.rb
gritter_notices-0.3.4 app/models/gritter_notice.rb
gritter_notices-0.3.3 app/models/gritter_notice.rb
gritter_notices-0.3.2 app/models/gritter_notice.rb