Class: Notifun::MessageTemplate
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Notifun::MessageTemplate
- Defined in:
- app/models/notifun/message_template.rb
Instance Method Summary collapse
- #backup_notification_methods ⇒ Object
- #default_notification_methods ⇒ Object
- #email? ⇒ Boolean
- #merge_fields_description ⇒ Object
- #merge_fields_display ⇒ Object
- #merge_fields_preview ⇒ Object
- #messages ⇒ Object
- #notification_methods ⇒ Object
- #possible_notification_methods ⇒ Object
- #push? ⇒ Boolean
- #sent_via ⇒ Object
- #to_param ⇒ Object
Instance Method Details
#backup_notification_methods ⇒ Object
33 34 35 |
# File 'app/models/notifun/message_template.rb', line 33 def backup_notification_methods (self[:backup_notification_methods] & Notifun.configuration.notification_methods) - default_notification_methods end |
#default_notification_methods ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'app/models/notifun/message_template.rb', line 24 def default_notification_methods notification_methods = self[:default_notification_methods] & Notifun.configuration.notification_methods if notification_methods.empty? notification_methods = self[:backup_notification_methods] & Notifun.configuration.notification_methods end notification_methods end |
#email? ⇒ Boolean
58 59 60 |
# File 'app/models/notifun/message_template.rb', line 58 def email? notification_methods.include?("email") end |
#merge_fields_description ⇒ Object
76 77 78 |
# File 'app/models/notifun/message_template.rb', line 76 def merge_fields_description merge_fields.reduce({}){|hash, (k,v)| hash[k] = v["description"] || v; hash} end |
#merge_fields_display ⇒ Object
80 81 82 83 84 85 86 |
# File 'app/models/notifun/message_template.rb', line 80 def merge_fields_display text = [] merge_fields_description.each do |key, description| text << "{#{key}} => #{description}" end text.join('<br>').html_safe end |
#merge_fields_preview ⇒ Object
72 73 74 |
# File 'app/models/notifun/message_template.rb', line 72 def merge_fields_preview merge_fields.reduce({}){|hash, (k,v)| hash[k] = v["preview"].presence || v["description"] || v; hash} end |
#messages ⇒ Object
20 21 22 |
# File 'app/models/notifun/message_template.rb', line 20 def Notifun::Message.where(message_template_key: key) end |
#notification_methods ⇒ Object
37 38 39 |
# File 'app/models/notifun/message_template.rb', line 37 def notification_methods default_notification_methods + backup_notification_methods end |
#possible_notification_methods ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/models/notifun/message_template.rb', line 41 def possible_notification_methods array = [] array << "push" if push_body.present? array << "email" if email_subject.present? array << "text" if text_body.present? if array.empty? notification_methods else array end end |
#push? ⇒ Boolean
54 55 56 |
# File 'app/models/notifun/message_template.rb', line 54 def push? notification_methods.include?("push") end |
#sent_via ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'app/models/notifun/message_template.rb', line 62 def sent_via text = default_notification_methods.join(' and ') if backup_notification_methods.any? text += " or " text += backup_notification_methods.join(', ') end text end |
#to_param ⇒ Object
6 7 8 |
# File 'app/models/notifun/message_template.rb', line 6 def to_param key end |