Class: Feste::Subscription

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/feste/subscription.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_subscribed_user(email) ⇒ Subscriber?

Return the subscriber based on an email address exists

Parameters:

  • (String)

Returns:

  • (Subscriber, nil)

    , the subscriber if one exists, or nil if none



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.options[:email_source] => email)
  end&.find_by(Feste.options[: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.

Parameters:

  • (Subscriber, ActionMailer::Base, Symbol)

Returns:

  • (String, nil)

    , the token or nil if a category cannot be found.



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_nameString

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.

Returns:

  • (String)


45
46
47
# File 'app/models/feste/subscription.rb', line 45

def category_name
  I18n.t("feste.categories.#{category}", default: category.titleize)
end