Sha256: 5524a96fff53bc29644233f2e642cea4055d74b5d199e80b524913e6f10ddc7f

Contents?: true

Size: 1.06 KB

Versions: 2

Compression:

Stored size: 1.06 KB

Contents

class Group < ActiveRecord::Base
  attr_accessor :_founder
  attr_accessor :_participants

  def followers
    subjects(:subject_type => :user, :direction => :senders)
  end

  after_create :create_founder
  after_create :create_participants
  
  def recent_groups
    subjects(:subject_type => :group, :direction => :receivers) do |q|
      q.select("ties.created_at").
        merge(Tie.recent)
    end
  end
 
  private

  #Creates the ties between the group and the founder
  def create_founder
    founder =
      Actor.find_by_permalink(_founder) || raise("Cannot create group without founder")

    sent_ties.create! :receiver => founder,
                      :relation => relations.sort.first
  end
  
  #Creates the ties betwbeen the group and the participants
  def create_participants
    
     return if @_participants.blank?
    
     @_participants.each do |participant|
      
      participant_actor = Actor.find_by_id(participant.to_i)

      sent_ties.create! :receiver => participant_actor,
                        :relation => relations.sort.first
     end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
social_stream-0.3.6 app/models/group.rb
social_stream-0.3.5 app/models/group.rb