Module: ActsAsSubscribable::SubscribableMethods::InstanceMethods

Defined in:
lib/acts_as_subscribable/subscribable_methods/instance_methods.rb

Instance Method Summary collapse

Instance Method Details

#subscribe(subscriber) ⇒ Object



8
9
10
# File 'lib/acts_as_subscribable/subscribable_methods/instance_methods.rb', line 8

def subscribe(subscriber)
  send(acts_as_subscribable_options[:subscriber].tableize).send(:<<, subscriber) unless subscribed?(subscriber)
end

#subscribed?(subscriber) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/acts_as_subscribable/subscribable_methods/instance_methods.rb', line 16

def subscribed?(subscriber)
  !subscriptions.where(:"#{acts_as_subscribable_options[:subscriber_id]}" => subscriber.id).empty?
end

#subscribersObject



4
5
6
# File 'lib/acts_as_subscribable/subscribable_methods/instance_methods.rb', line 4

def subscribers
  send acts_as_subscribable_options[:subscriber].tableize
end

#unsubscribe(subscriber) ⇒ Object



12
13
14
# File 'lib/acts_as_subscribable/subscribable_methods/instance_methods.rb', line 12

def unsubscribe(subscriber)
  subscriber.subscriptions.where(:"#{acts_as_subscribable_options[:subscribed_id]}" => id).delete_all
end