Module: ActsAsNewsletter::Model
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/acts_as_newsletter/model.rb,
lib/acts_as_newsletter/model/config.rb
Defined Under Namespace
Modules: ClassMethods Classes: Config
Instance Attribute Summary collapse
-
#chunk_sent ⇒ Object
Boolean allowing us to know if we sent the last emails chunk.
Instance Method Summary collapse
-
#available_emails ⇒ Object
Parses all available e-mails stored in recpients field.
-
#emails ⇒ Object
Takes emails from the list and delete them from it.
-
#newsletter_config ⇒ Object
Newsletter configuration passed to the block.
-
#prepare_emails ⇒ Object
Prepare model to handle e-mail sending collecting e-mails and initializing counters.
- #send_newsletter! ⇒ Object
Instance Attribute Details
#chunk_sent ⇒ Object
Boolean allowing us to know if we sent the last emails chunk
109 110 111 |
# File 'lib/acts_as_newsletter/model.rb', line 109 def chunk_sent @chunk_sent end |
Instance Method Details
#available_emails ⇒ Object
Parses all available e-mails stored in recpients field
129 130 131 |
# File 'lib/acts_as_newsletter/model.rb', line 129 def available_emails @available_emails ||= recipients.split("|") end |
#emails ⇒ Object
Takes emails from the list and delete them from it
134 135 136 |
# File 'lib/acts_as_newsletter/model.rb', line 134 def emails @emails ||= available_emails.shift(emails_chunk_size) end |
#newsletter_config ⇒ Object
Newsletter configuration passed to the block
112 113 114 115 |
# File 'lib/acts_as_newsletter/model.rb', line 112 def @newsletter_config ||= Model::Config.new(self, &self.class.config_proc).config end |
#prepare_emails ⇒ Object
Prepare model to handle e-mail sending collecting e-mails and initializing counters
121 122 123 124 125 126 |
# File 'lib/acts_as_newsletter/model.rb', line 121 def prepare_emails emails_list = [:emails] self.recipients_count = emails_list.length self.sent_count = 0 self.recipients = emails_list.join("|") end |
#send_newsletter! ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/acts_as_newsletter/model.rb', line 138 def prepare_sending! if state_name == :ready # Get config from newsletter config mail_config_keys = [:template_path, :template_name, :layout, :from] config = .select do |key, value| mail_config_keys.include?(key) and value end # Send e-mail to each recipient emails.each do |email| ActsAsNewsletter::Mailer.(self, email, config).deliver end self.chunk_sent = true save end |