Module: SubscribedTo::ClassMethods
- Defined in:
- lib/subscribed_to.rb
Instance Method Summary collapse
-
#list_id ⇒ Object
Returns the list id for the class as defined in mail_chimp.
-
#merge_vars ⇒ Object
Returns the hash of merge vars for the class as defined in mail_chimp.
-
#subscribed_to(id) ⇒ Object
Enable SubscribedTo in your user model.
Instance Method Details
#list_id ⇒ Object
Returns the list id for the class as defined in mail_chimp
64 65 66 |
# File 'lib/subscribed_to.rb', line 64 def list_id SubscribedTo.mail_chimp_config.lists[@list_key][:id] end |
#merge_vars ⇒ Object
Returns the hash of merge vars for the class as defined in mail_chimp
69 70 71 |
# File 'lib/subscribed_to.rb', line 69 def merge_vars SubscribedTo.mail_chimp_config.lists[@list_key][:merge_vars] end |
#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
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/subscribed_to.rb', line 46 def subscribed_to(id) include InstanceMethods include MailChimp::InstanceMethods if SubscribedTo.service == :mail_chimp @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 |