Class: Pechkin::MessageTemplate

Inherits:
Object
  • Object
show all
Defined in:
lib/pechkin/message_template.rb

Overview

Message template to render final message.

Constant Summary collapse

ERB_INITIALIZE_KEYWORD_ARGUMENTS =
ERB.instance_method(:initialize)
.parameters.assoc(:key)

Instance Method Summary collapse

Constructor Details

#initialize(erb) ⇒ MessageTemplate

Returns a new instance of MessageTemplate.



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/pechkin/message_template.rb', line 14

def initialize(erb)
  # ERB#initialize has different signature starting from Ruby 2.6.*
  # See link:
  # https://github.com/ruby/ruby/blob/2311087/NEWS#stdlib-updates-outstanding-ones-only
  if MessageTemplate::ERB_INITIALIZE_KEYWORD_ARGUMENTS # Ruby 2.6+
    @erb_template = ERB.new(erb, trim_mode: '-')
  else
    trim_mode = '-'
    @erb_template = ERB.new(erb, trim_mode: trim_mode)
  end
end

Instance Method Details

#render(data) ⇒ Object



26
27
28
# File 'lib/pechkin/message_template.rb', line 26

def render(data)
  MessageBinding.new(data).render_template(@erb_template)
end