Class: WelcomeCycle::Email
- Inherits:
-
Object
- Object
- WelcomeCycle::Email
- Defined in:
- lib/welcome_cycle/email.rb
Instance Method Summary collapse
- #days_into_cycle(*days) ⇒ Object
- #days_offset_from_cycle_end(*days) ⇒ Object
- #deliver(r) ⇒ Object
-
#initialize(name, &block) ⇒ Email
constructor
A new instance of Email.
- #recipients ⇒ Object
- #scope(&block) ⇒ Object
- #send_to_recipients! ⇒ Object
Constructor Details
#initialize(name, &block) ⇒ Email
Returns a new instance of Email.
5 6 7 8 9 10 |
# File 'lib/welcome_cycle/email.rb', line 5 def initialize(name, &block) @name = name instance_eval &block raise "You must specify at least one day to send this email by specifying 'days_into_cycle' and/or 'days_offset_from_cycle_end'" if @days_into_cycle.nil? && @days_offset_from_cycle_end.nil? WelcomeCycle::EmailRegister.instance << self end |
Instance Method Details
#days_into_cycle(*days) ⇒ Object
12 13 14 15 16 |
# File 'lib/welcome_cycle/email.rb', line 12 def days_into_cycle(*days) raise ArgumentError, "'days_into_cycle' can only contain positive numbers" if days.detect { |d| d <= 0 } raise "When specifying 'days_into_cycle' you must set the 'welcome_cycle_start_date'. See README config section" if WelcomeCycle.config.welcome_cycle_start_date.nil? @days_into_cycle = days end |
#days_offset_from_cycle_end(*days) ⇒ Object
18 19 20 21 |
# File 'lib/welcome_cycle/email.rb', line 18 def days_offset_from_cycle_end(*days) raise "When specifying 'days_offset_from_cycle_end' you must set the 'welcome_cycle_end_date' config section" if WelcomeCycle.config.welcome_cycle_end_date.nil? @days_offset_from_cycle_end = days end |
#deliver(r) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/welcome_cycle/email.rb', line 37 def deliver(r) if defined?(Delayed) && (defined?(Delayed::Job) || defined?(Delayed::Worker)) deliver_via_delayed_job(r) else deliver_directly(r) end end |
#recipients ⇒ Object
31 32 33 34 35 |
# File 'lib/welcome_cycle/email.rb', line 31 def recipients recipients = WelcomeCycle.config.base_class recipients = recipients.where(date_conditions) @scope_chain.nil? ? recipients.all : recipients.instance_eval(&@scope_chain) end |
#scope(&block) ⇒ Object
23 24 25 |
# File 'lib/welcome_cycle/email.rb', line 23 def scope(&block) @scope_chain = block end |
#send_to_recipients! ⇒ Object
27 28 29 |
# File 'lib/welcome_cycle/email.rb', line 27 def send_to_recipients! recipients.each { |r| deliver(r) } end |