Module: Windbag::UserClass

Defined in:
lib/windbag/user_class.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
6
7
8
9
10
11
12
# File 'lib/windbag/user_class.rb', line 3

def self.included(base)
  base.class_eval do
    has_one  :windbag_channel, :as => :owner, :dependent => :destroy, :class_name => 'Windbag::Channel'
    has_many :windbag_subscriptions, :class_name => 'Windbag::Subscription'
    has_many :windbag_channels, :through => :windbag_subscriptions, :class_name => 'Windbag::Channel', :source => :channel

    after_create :subscribe_to_global_channel
    after_create :create_private_channel
  end
end

Instance Method Details

#notificationsObject



25
26
27
28
29
30
31
# File 'lib/windbag/user_class.rb', line 25

def notifications
   notifications = []
   windbag_channels.each do |channel|
     notifications << channel.notifications
   end
   notifications.flatten
end

#subscribe(channel) ⇒ Object



15
16
17
18
# File 'lib/windbag/user_class.rb', line 15

def subscribe(channel)
  Subscription.find_or_create_by_user_id_and_channel_id(self.id, channel.id)
  self
end

#unsubscribe(channel) ⇒ Object



20
21
22
23
# File 'lib/windbag/user_class.rb', line 20

def unsubscribe(channel)
  Subscription.destroy_all(:user_id => self.id, :channel_id => channel.id)
  self
end