class NotifyTemplate
Attributes
Public Class Methods
Source
# File app/lib/notify_template.rb, line 28 def all_ids(channel:) local_templates(channel).values.map(&:id).freeze end
Source
# File app/lib/notify_template.rb, line 24 def exists?(name, channel:) local_templates(channel).key?(name) end
Source
# File app/lib/notify_template.rb, line 14 def find(name, channel:) local_templates(channel)[name] end
Source
# File app/lib/notify_template.rb, line 18 def find_by_id(template_id, channel:) return nil if template_id.blank? local_templates(channel).values.find { _1.id == template_id.to_s } end
Source
# File app/lib/notify_template.rb, line 63 def initialize(name:, channel:, content:) @name = name.to_sym @channel = channel.to_sym frontmatter, @body = parse_frontmatter(content) @id = frontmatter["template_id"] @subject = frontmatter["subject"].to_s @purpose = frontmatter["purpose"]&.to_sym end
Public Instance Methods
Source
# File app/lib/notify_template.rb, line 72 def render(personalisation) ctx = personalisation.instance_eval { binding } body = ERB.new(@body, trim_mode: "-").result(ctx) return { body: } if @channel == :sms { subject: ERB.new(@subject, trim_mode: nil).result(ctx), body: } rescue NameError => e raise NameError, "#{e.message} in #{@channel} template '#{@name}'" end