Class: Notifun::MessageTemplate

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/notifun/message_template.rb

Instance Method Summary collapse

Instance Method Details

#backup_notification_methodsObject



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_methodsObject



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

Returns:

  • (Boolean)


58
59
60
# File 'app/models/notifun/message_template.rb', line 58

def email?
  notification_methods.include?("email")
end

#merge_fields_descriptionObject



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_displayObject



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_previewObject



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

#messagesObject



20
21
22
# File 'app/models/notifun/message_template.rb', line 20

def messages
  Notifun::Message.where(message_template_key: key)
end

#notification_methodsObject



37
38
39
# File 'app/models/notifun/message_template.rb', line 37

def notification_methods
  default_notification_methods + backup_notification_methods
end

#possible_notification_methodsObject



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

Returns:

  • (Boolean)


54
55
56
# File 'app/models/notifun/message_template.rb', line 54

def push?
  notification_methods.include?("push")
end

#sent_viaObject



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_paramObject



6
7
8
# File 'app/models/notifun/message_template.rb', line 6

def to_param
  key
end