Module: SubscribedTo::ClassMethods

Defined in:
lib/subscribed_to.rb

Instance Method Summary collapse

Instance Method Details

#subscribed_to(id) ⇒ Object

Enable SubscribedTo in your user model. The only paramter it takes is a symbol which corresponds to a list in the mail_chimp_config.lists hash.

subscribed_to :mailing_list


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/subscribed_to.rb', line 54

def subscribed_to(id)
  if SubscribedTo.active  # don't activate all the gem goodies if we're not active
    include InstanceMethods
    if SubscribedTo.service == :mail_chimp
      extend MailChimp::ClassMethods
      include MailChimp::InstanceMethods
    end

    @list_key = id.to_sym

    # We need to reference which models are enabled, and which list they belong to when processing the webhooks.
    SubscribedTo.mail_chimp_config.enabled_models[self.list_id].blank? ?
      SubscribedTo.mail_chimp_config.enabled_models[self.list_id] = [self.to_s] :
      SubscribedTo.mail_chimp_config.enabled_models[self.list_id] << self.to_s

    class_eval do
      after_create :subscribe_to_list
      after_update :update_list_member
    end
  end
end