Sha256: 87c956e455d20a61303932a11deb24ee664aaed60f2f9217ec71b0034b633053

Contents?: true

Size: 1.72 KB

Versions: 1

Compression:

Stored size: 1.72 KB

Contents

# == Schema Information
#
# Table name: activities
#
#  id            :integer(4)      not null, primary key
#  item_id       :integer(4)
#  item_type     :string(255)
#  template      :string(255)
#  source_id     :integer(4)
#  source_type   :string(255)
#  content       :text
#  title         :string(255)
#  status_update :boolean(1)
#  created_at    :datetime
#  updated_at    :datetime
#

class Activity < ActiveRecord::Base  

  belongs_to :item, :polymorphic => true
  belongs_to :source, :polymorphic => true
  has_many :activity_feeds
  
  validates_presence_of :source
      
  named_scope :since, lambda { |time| {:conditions => ["activities.created_at > ?", time] } }
  named_scope :before, lambda {|time| {:conditions => ["activities.created_at < ?", time] } }
  named_scope :recent, :order => "activities.created_at DESC"
  named_scope :after, lambda {|id| {:conditions => ["activities.id > ?", id] } }
  named_scope :only_public, :conditions => ["activities.is_public = true"]
  named_scope :filter_by_template, lambda { |template| {:conditions => ["activities.template = ?", template || '%'] } }
  
  def validate
    errors.add_to_base(I18n.t('muck.activities.template_or_item_required')) if template.blank? && item.blank?
  end
    
  # Provides a template that can be used to render a view of this activity.
  # If 'template' is not specified when the object created then the item class
  # name will be used to generated a template
  def partial
    template || item.class.name.underscore
  end

  # Checks to see if the specified object can edit this activity.
  # Most likely check_object will be a user
  def can_edit?(check_object)
    return true if check_object.is_a?(User) && check_object.admin?
    source == check_object
  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
muck-activity-0.1.3 app/models/activity.rb