Class: MailyHerald::Dispatch
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- MailyHerald::Dispatch
- Defined in:
- app/models/maily_herald/dispatch.rb
Overview
Instance Attribute Summary collapse
-
#absolute_delay ⇒ String
Email delivery delay from beginning of sequence.
-
#conditions ⇒ String
Delivery conditions as Liquid expression.
-
#from ⇒ String
Sender email address.
-
#list_id ⇒ Fixnum
List association id.
-
#mailer_name ⇒ String
Mailer class name.
-
#name ⇒ String
Dispatch name.
-
#override_subscription ⇒ String
Defines whether email should be sent regardless of entity subscription state.
-
#period ⇒ String
Email delivery period.
-
#sequence_id ⇒ Fixnum
Sequence association id.
-
#state ⇒ Object
Returns dispatch state as symbol.
-
#subject ⇒ String
Email subject as Liquid template.
-
#template ⇒ String
Email body template as Liquid template.
-
#title ⇒ String
Dispatch title.
-
#type ⇒ String
Polymorphic type.
Instance Method Summary collapse
- #archive ⇒ Object
- #archive! ⇒ Object
- #archived? ⇒ Boolean
- #disable ⇒ Object
- #disable! ⇒ Object
- #disabled? ⇒ Boolean
- #enable ⇒ Object
- #enable! ⇒ Object
- #enabled? ⇒ Boolean
- #has_start_at_proc? ⇒ Boolean
- #in_scope?(entity) ⇒ Boolean
-
#list=(l) ⇒ Object
Sets List associated with this dispatch.
-
#locked? ⇒ Boolean
Check if dispatch is locked.
-
#processable?(entity) ⇒ Boolean
Checks if dispatch can be sent to given entity.
-
#start_at ⇒ Object
Returns time as string with Liquid expression or Proc.
-
#start_at=(v) ⇒ Object
Sets start_at value of OneTimeMailing, PeriodicalMailing and SequenceMailing.
- #start_at_changed? ⇒ Boolean
- #subscription_valid?(entity) ⇒ Boolean
Instance Attribute Details
#absolute_delay ⇒ String
Email delivery delay from beginning of sequence. Valid only for SequenceMailing.
33 34 35 |
# File 'app/models/maily_herald/dispatch.rb', line 33 def absolute_delay @absolute_delay end |
#conditions ⇒ String
Delivery conditions as Liquid expression.
33 34 35 |
# File 'app/models/maily_herald/dispatch.rb', line 33 def conditions @conditions end |
#from ⇒ String
Sender email address. If not provided, action_mailer.default_options[:from} is used. Valid only for Mailing.
33 34 35 |
# File 'app/models/maily_herald/dispatch.rb', line 33 def from @from end |
#list_id ⇒ Fixnum
List association id.
33 34 35 |
# File 'app/models/maily_herald/dispatch.rb', line 33 def list_id @list_id end |
#mailer_name ⇒ String
33 34 35 |
# File 'app/models/maily_herald/dispatch.rb', line 33 def mailer_name @mailer_name end |
#name ⇒ String
Dispatch name.
33 34 35 |
# File 'app/models/maily_herald/dispatch.rb', line 33 def name @name end |
#override_subscription ⇒ String
Defines whether email should be sent regardless of entity subscription state.
33 34 35 |
# File 'app/models/maily_herald/dispatch.rb', line 33 def override_subscription @override_subscription end |
#period ⇒ String
Email delivery period. Valid only for PeriodicalMailing.
33 34 35 |
# File 'app/models/maily_herald/dispatch.rb', line 33 def period @period end |
#sequence_id ⇒ Fixnum
Sequence association id.
33 34 35 |
# File 'app/models/maily_herald/dispatch.rb', line 33 def sequence_id @sequence_id end |
#state ⇒ Object
Returns dispatch state as symbol
33 34 35 |
# File 'app/models/maily_herald/dispatch.rb', line 33 def state @state end |
#subject ⇒ String
Email subject as Liquid template. Valid only for Mailing.
33 34 35 |
# File 'app/models/maily_herald/dispatch.rb', line 33 def subject @subject end |
#template ⇒ String
Email body template as Liquid template. Valid only for Mailing.
33 34 35 |
# File 'app/models/maily_herald/dispatch.rb', line 33 def template @template end |
#title ⇒ String
Dispatch title.
33 34 35 |
# File 'app/models/maily_herald/dispatch.rb', line 33 def title @title end |
#type ⇒ String
Polymorphic type.
33 34 35 |
# File 'app/models/maily_herald/dispatch.rb', line 33 def type @type end |
Instance Method Details
#archive ⇒ Object
131 132 133 |
# File 'app/models/maily_herald/dispatch.rb', line 131 def archive write_attribute(:state, "archived") end |
#archive! ⇒ Object
121 122 123 |
# File 'app/models/maily_herald/dispatch.rb', line 121 def archive! update_attribute(:state, "archived") end |
#archived? ⇒ Boolean
111 112 113 |
# File 'app/models/maily_herald/dispatch.rb', line 111 def archived? self.state == :archived end |
#disable ⇒ Object
128 129 130 |
# File 'app/models/maily_herald/dispatch.rb', line 128 def disable write_attribute(:state, "disabled") end |
#disable! ⇒ Object
118 119 120 |
# File 'app/models/maily_herald/dispatch.rb', line 118 def disable! update_attribute(:state, "disabled") end |
#disabled? ⇒ Boolean
108 109 110 |
# File 'app/models/maily_herald/dispatch.rb', line 108 def disabled? self.state == :disabled end |
#enable ⇒ Object
125 126 127 |
# File 'app/models/maily_herald/dispatch.rb', line 125 def enable write_attribute(:state, "enabled") end |
#enable! ⇒ Object
115 116 117 |
# File 'app/models/maily_herald/dispatch.rb', line 115 def enable! update_attribute(:state, "enabled") end |
#enabled? ⇒ Boolean
105 106 107 |
# File 'app/models/maily_herald/dispatch.rb', line 105 def enabled? self.state == :enabled end |
#has_start_at_proc? ⇒ Boolean
88 89 90 |
# File 'app/models/maily_herald/dispatch.rb', line 88 def has_start_at_proc? !!(@start_at_proc || MailyHerald.start_at_procs[self.id]) end |
#in_scope?(entity) ⇒ Boolean
147 148 149 |
# File 'app/models/maily_herald/dispatch.rb', line 147 def in_scope? entity self.list.context.scope.exists?(entity) end |
#list=(l) ⇒ Object
Sets List associated with this dispatch
138 139 140 141 |
# File 'app/models/maily_herald/dispatch.rb', line 138 def list= l l = MailyHerald::List.find_by_name(l.to_s) if l.is_a?(String) || l.is_a?(Symbol) super(l) end |
#locked? ⇒ Boolean
Check if dispatch is locked.
165 166 167 |
# File 'app/models/maily_herald/dispatch.rb', line 165 def locked? MailyHerald.dispatch_locked?(self.name) end |
#processable?(entity) ⇒ Boolean
Checks if dispatch can be sent to given entity.
Following checks are performed:
-
dispatch is enabled,
-
subscription is overriden or user is subscribed to dispatch list,
-
entity belongs to list Context scope.
159 160 161 |
# File 'app/models/maily_herald/dispatch.rb', line 159 def processable? entity self.enabled? && subscription_valid?(entity) && in_scope?(entity) end |
#start_at ⇒ Object
Returns time as string with Liquid expression or Proc.
84 85 86 |
# File 'app/models/maily_herald/dispatch.rb', line 84 def start_at @start_at_proc || MailyHerald.start_at_procs[self.id] || read_attribute(:start_at) end |
#start_at=(v) ⇒ Object
Sets start_at value of OneTimeMailing, PeriodicalMailing and SequenceMailing.
75 76 77 78 79 80 81 |
# File 'app/models/maily_herald/dispatch.rb', line 75 def start_at= v if v.respond_to? :call @start_at_proc = v else super(v.is_a?(Time) ? v.to_s : v) end end |
#start_at_changed? ⇒ Boolean
92 93 94 95 96 97 98 |
# File 'app/models/maily_herald/dispatch.rb', line 92 def start_at_changed? if has_start_at_proc? @start_at_proc != MailyHerald.start_at_procs[self.id] else super end end |
#subscription_valid?(entity) ⇒ Boolean
143 144 145 |
# File 'app/models/maily_herald/dispatch.rb', line 143 def subscription_valid? entity self.override_subscription? || self.list.subscribed?(entity) end |