Module: Subscribable::RelationAssigner
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/subscribable/relation_assigner.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/subscribable/relation_assigner.rb', line 51
def method_missing(method_name, *args, &block)
class_name = klass_name(method_name)
case method_name.to_s
when /_subscribers/
subscribers_query(method_name, class_name)
when /_subscriptions/
subscriptions_query(method_name, class_name)
else
super
end
end
|
Instance Method Details
#delete_subscription_to!(actor) ⇒ Object
25
26
27
28
|
# File 'lib/subscribable/relation_assigner.rb', line 25
def delete_subscription_to!(actor)
subscription = subscription_with(actor)
subscription.delete
end
|
#respond_to?(method_name, include_all = false) ⇒ Boolean
46
47
48
49
|
# File 'lib/subscribable/relation_assigner.rb', line 46
def respond_to?(method_name, include_all=false)
class_name = klass_name(method_name)
method_name.to_s.match('_subscri') ? class_name.constantize.respond_to?(:subscribable?) : super
end
|
#subscribe_to!(actor) ⇒ Object
19
20
21
22
23
|
# File 'lib/subscribable/relation_assigner.rb', line 19
def subscribe_to!(actor)
sub = subscriptions.new
sub.subscription = actor
sub.save
end
|
#subscribed_to?(actor) ⇒ Boolean
41
42
43
44
|
# File 'lib/subscribable/relation_assigner.rb', line 41
def subscribed_to?(actor)
query = actor.subscribers.where(subscriber_id: id, subscriber_type: self.class.name)
query.empty? ? false : true
end
|
#subscription_status_with(actor) ⇒ Object
30
31
32
33
|
# File 'lib/subscribable/relation_assigner.rb', line 30
def subscription_status_with(actor)
subscription = subscription_with(actor)
subscription.nil? ? 'no relationship' : subscription.status
end
|
#update_subscription_status!(actor, status) ⇒ Object
35
36
37
38
39
|
# File 'lib/subscribable/relation_assigner.rb', line 35
def update_subscription_status!(actor, status)
subscription = subscription_with(actor)
subscription.status = status
subscription.save
end
|