Class: Eql::TemplateLoader
- Inherits:
-
Object
- Object
- Eql::TemplateLoader
- Extended by:
- Forwardable
- Defined in:
- lib/eql/template_loader.rb
Overview
Loader class loads templates and caches them.
Instance Attribute Summary collapse
- #builder ⇒ Eql::Builder readonly
Class Method Summary collapse
-
.cache ⇒ Hash{String => String}
Templates cache.
Instance Method Summary collapse
-
#initialize(builder) ⇒ TemplateLoader
constructor
A new instance of TemplateLoader.
-
#load_file(path) ⇒ String
private
Load file’s content.
-
#load_template(name) ⇒ String
Load builder template.
-
#resolve_path(file) ⇒ String
private
Resolve file’s path.
-
#template_path(file) ⇒ String
private
File template to find.
Constructor Details
#initialize(builder) ⇒ TemplateLoader
Returns a new instance of TemplateLoader.
16 17 18 |
# File 'lib/eql/template_loader.rb', line 16 def initialize(builder) @builder = builder end |
Instance Attribute Details
#builder ⇒ Eql::Builder (readonly)
11 12 13 |
# File 'lib/eql/template_loader.rb', line 11 def builder @builder end |
Class Method Details
.cache ⇒ Hash{String => String}
Templates cache
85 86 87 |
# File 'lib/eql/template_loader.rb', line 85 def self.cache @cache ||= {} end |
Instance Method Details
#load_file(path) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Load file’s content
42 43 44 |
# File 'lib/eql/template_loader.rb', line 42 def load_file(path) File.read(path) end |
#load_template(name) ⇒ String
Load builder template
27 28 29 30 31 |
# 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) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Resolve file’s path
73 74 75 76 77 78 |
# File 'lib/eql/template_loader.rb', line 73 def resolve_path(file) path = template_path(file) Dir.glob(path).first.tap do |f| raise "Unable to find query template with #{path.inspect} location" unless f end end |
#template_path(file) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
File template to find
55 56 57 58 59 60 |
# File 'lib/eql/template_loader.rb', line 55 def template_path(file) [ File.join(@builder.path.to_s, file.to_s), @builder.adapter.extension ].join end |