Class: Bearcat::RateLimiting::RedisScript::TemplateContext

Inherits:
Object
  • Object
show all
Defined in:
lib/bearcat/rate_limiting/redis_script.rb

Instance Method Summary collapse

Constructor Details

#initialize(script_path) ⇒ TemplateContext

Returns a new instance of TemplateContext.



71
72
73
# File 'lib/bearcat/rate_limiting/redis_script.rb', line 71

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

Parameters:

  • relative_path (String)

    the relative path to the script from ‘script_path`



84
85
86
87
88
89
# File 'lib/bearcat/rate_limiting/redis_script.rb', line 84

def include_partial(relative_path)
  unless @partial_templates.has_key? relative_path
    @partial_templates[relative_path] = nil
    template( Pathname.new("#{@script_path}/#{relative_path}") )
  end
end

#template(pathname) ⇒ Object



75
76
77
78
# File 'lib/bearcat/rate_limiting/redis_script.rb', line 75

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