Class: Moist::SubscriptionManager
- Inherits:
-
Object
- Object
- Moist::SubscriptionManager
- Defined in:
- lib/moist/subscription_manager.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#subscriber ⇒ Object
readonly
Returns the value of attribute subscriber.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #call(*campaign_slugs) ⇒ Object (also: #to, #from)
-
#initialize(subscriber, user:, action:) ⇒ SubscriptionManager
constructor
A new instance of SubscriptionManager.
Constructor Details
#initialize(subscriber, user:, action:) ⇒ SubscriptionManager
Returns a new instance of SubscriptionManager.
4 5 6 7 8 |
# File 'lib/moist/subscription_manager.rb', line 4 def initialize(subscriber, user:, action:) @subscriber = subscriber @user = user @action = action end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
3 4 5 |
# File 'lib/moist/subscription_manager.rb', line 3 def action @action end |
#subscriber ⇒ Object (readonly)
Returns the value of attribute subscriber.
3 4 5 |
# File 'lib/moist/subscription_manager.rb', line 3 def subscriber @subscriber end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
3 4 5 |
# File 'lib/moist/subscription_manager.rb', line 3 def user @user end |
Instance Method Details
#call(*campaign_slugs) ⇒ Object Also known as: to, from
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/moist/subscription_manager.rb', line 10 def call(*campaign_slugs) campaign_slugs.map do |campaign_slug| campaign = ::Moist::Campaign[campaign_slug] if @action == :subscribe ::Moist::CampaignSubscriber.first_or_create!(subscriber: subscriber, user: user, moist_campaign: campaign) elsif @action == :unsubscribe sub = ::Moist::CampaignSubscriber.find_by!(subscriber: subscriber, user: user, moist_campaign: campaign) sub.destroy! sub end end end |