Skip to content

Commit c00ef2a

Browse files
committed
ConfigurationFile: skip ERB rendering unless the file seem to contain ERB
Uncached ERB rendering is very costly, so assuming many files don't actually contain ERB, it's worth checking for it first. For ERB file, we could consider caching the compilation, but it's more complicated.
1 parent daaa87c commit c00ef2a

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

activesupport/lib/active_support/configuration_file.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ def self.parse(content_path, **options)
1919
end
2020

2121
def parse(context: nil, **options)
22-
source = render(context)
22+
source = @content.include?("<%") ? render(context) : @content
23+
2324
if source == @content
2425
if YAML.respond_to?(:unsafe_load)
2526
YAML.unsafe_load_file(@content_path, **options) || {}
@@ -42,7 +43,6 @@ def parse(context: nil, **options)
4243
private
4344
def read(content_path)
4445
require "yaml" unless defined?(YAML)
45-
require "erb" unless defined?(ERB)
4646

4747
File.read(content_path).tap do |content|
4848
if content.include?("\u00A0")
@@ -52,6 +52,7 @@ def read(content_path)
5252
end
5353

5454
def render(context)
55+
require "erb" unless defined?(ERB)
5556
erb = ERB.new(@content).tap { |e| e.filename = @content_path }
5657
context ? erb.result(context) : erb.result
5758
end

0 commit comments

Comments
 (0)