Class: SidekiqUniqueJobs::Script::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq_unique_jobs/script/template.rb

Overview

Class Template provides LUA script partial template rendering

Author:

Instance Method Summary collapse

Constructor Details

#initialize(script_path) ⇒ Template

Returns a new instance of Template.



14
15
16
# File 'lib/sidekiq_unique_jobs/script/template.rb', line 14

def initialize(script_path)
  @script_path = script_path
end

Instance Method Details

#include_partial(relative_path) ⇒ Object

helper method to include a lua partial within another lua script



33
34
35
36
37
38
# File 'lib/sidekiq_unique_jobs/script/template.rb', line 33

def include_partial(relative_path)
  return if @partial_templates.key?(relative_path)

  @partial_templates[relative_path] = nil
  render(Pathname.new("#{@script_path}/#{relative_path}"))
end

#render(pathname) ⇒ String

Renders a Lua script and includes any partials in that file

all `<%= include_partial '' %>` replaced with the actual contents of the partial

Parameters:

  • pathname (Pathname)

    the path to the

Returns:

  • (String)

    the rendered Luascript



26
27
28
29
# File 'lib/sidekiq_unique_jobs/script/template.rb', line 26

def render(pathname)
  @partial_templates ||= {}
  ::ERB.new(File.read(pathname)).result(binding)
end