Skip to content

Commit 6395186

Browse files
authored
Merge pull request rails#52667 from Shopify/optimize-config-file-further
ConfigurationFile: skip ERB rendering unless the file seem to contain ERB
2 parents c3d8dc4 + c00ef2a commit 6395186

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)