class Eql::TemplateLoader
Loader class loads templates and caches them.
Attributes
builder[R]
@return [Eql::Builder]
Public Class Methods
cache()
click to toggle source
Templates cache
@return [Hash{String => String}]
# File lib/eql/template_loader.rb, line 88 def self.cache @cache ||= {} end
new(builder)
click to toggle source
@param [Eql::Builder] builder
# File lib/eql/template_loader.rb, line 16 def initialize(builder) @builder = builder end
Public Instance Methods
load_file(path)
click to toggle source
Load file's content
@api private
@param [String] path file's path
@return [String]
# File lib/eql/template_loader.rb, line 42 def load_file(path) File.read(path) end
load_template(name)
click to toggle source
Load builder template
@param [String, Symbol] name template's name
@return [String] returns loaded template
# File lib/eql/template_loader.rb, line 27 def load_template(name) path = resolve_path(name) return load_file(path) unless Eql.config.cache_templates? cache[path] ||= load_file(path) end
resolve_path(file)
click to toggle source
Resolve file's path
@api private
@raise [RuntimeError] when can't wind a file
@param [String] file template's name
@return [String] returns template's path
# File lib/eql/template_loader.rb, line 72 def resolve_path(file) paths = template_path(file) paths.each do |path| filepath = Dir.glob(path).first return filepath if filepath.present? end raise "Unable to find query template with #{paths.inspect} location" end
template_path(file)
click to toggle source
File template to find
@api private
@param [String, Symbol] file template's name
@return [Array<String>] returns file path pattern
# File lib/eql/template_loader.rb, line 55 def template_path(file) @builder.path.map do |path| [File.join(path, file.to_s), @builder.adapter.extension].join end end