Class: Feste::Subscription
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Feste::Subscription
- Defined in:
- app/models/feste/subscription.rb
Class Method Summary collapse
-
.find_subscribed_user(email) ⇒ Subscriber?
Return the subscriber based on an email address exists.
-
.get_token_for(subscriber, mailer, action) ⇒ String?
Return the propper subscription token based on the propper subscriber and email category If the subscription does not exist, one is created in order to return the token.
Instance Method Summary collapse
-
#category_name ⇒ String
Return the human readable version of a category name.
Class Method Details
.find_subscribed_user(email) ⇒ Subscriber?
Return the subscriber based on an email address exists
33 34 35 36 37 |
# File 'app/models/feste/subscription.rb', line 33 def self.find_subscribed_user(email) user_models.find do |model| model.find_by(Feste.[:email_source] => email) end&.find_by(Feste.[:email_source] => email) end |
.get_token_for(subscriber, mailer, action) ⇒ String?
Return the propper subscription token based on the propper subscriber and email category If the subscription does not exist, one is created in order to return the token. If the action is not categorized, then the subscription is not created, and nil is returned.
16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/models/feste/subscription.rb', line 16 def self.get_token_for(subscriber, mailer, action) transaction do category = mailer.action_categories[action.to_sym] || mailer.action_categories[:all] subscription = Feste::Subscription.find_or_create_by( subscriber: subscriber, category: category ) subscription.token end end |
Instance Method Details
#category_name ⇒ String
Return the human readable version of a category name.
Checks to see if there is an i18n key corresponding to the category. If not, then the category is titleized.
45 46 47 |
# File 'app/models/feste/subscription.rb', line 45 def category_name I18n.t("feste.categories.#{category}", default: category.titleize) end |