From 8c70682d6b757952b26f558ae8f6d54a2097a081 Mon Sep 17 00:00:00 2001 From: Justin Li Date: Thu, 4 Dec 2014 17:39:41 -0500 Subject: [PATCH] Don't automatically load hooks --- lib/liquid.rb | 4 ---- lib/liquid/profiler.rb | 8 +++++++- lib/liquid/profiler/hooks.rb | 6 ------ lib/liquid/template.rb | 2 +- test/test_helper.rb | 1 + 5 files changed, 9 insertions(+), 12 deletions(-) diff --git a/lib/liquid.rb b/lib/liquid.rb index cacb0d83..70d26def 100644 --- a/lib/liquid.rb +++ b/lib/liquid.rb @@ -41,10 +41,6 @@ module Liquid singleton_class.send(:attr_accessor, :cache_classes) self.cache_classes = true - - def self.load_profiler_hooks - require 'liquid/profiler/hooks' - end end require "liquid/version" diff --git a/lib/liquid/profiler.rb b/lib/liquid/profiler.rb index a90c3030..f253e2d4 100644 --- a/lib/liquid/profiler.rb +++ b/lib/liquid/profiler.rb @@ -71,7 +71,13 @@ module Liquid end def self.hooks_loaded - false + @hooks_loaded + end + + def self.load_hooks + return if @hooks_loaded + require 'liquid/profiler/hooks' + @hooks_loaded = true end def self.profile_token_render(token) diff --git a/lib/liquid/profiler/hooks.rb b/lib/liquid/profiler/hooks.rb index fc2736a2..8a6e8083 100644 --- a/lib/liquid/profiler/hooks.rb +++ b/lib/liquid/profiler/hooks.rb @@ -1,10 +1,4 @@ module Liquid - class Profiler - def self.hooks_loaded - true - end - end - class BlockBody def render_token_with_profiling(token, context) Profiler.profile_token_render(token) do diff --git a/lib/liquid/template.rb b/lib/liquid/template.rb index d143dfdb..e10d4296 100644 --- a/lib/liquid/template.rb +++ b/lib/liquid/template.rb @@ -250,7 +250,7 @@ module Liquid def with_profiling if @profiling && !@options[:included] - Liquid.load_profiler_hooks unless Profiler.hooks_loaded + raise "Profiler hooks not loaded, call Liquid::Profiler.load_hooks first" unless Profiler.hooks_loaded @profiler = Profiler.new @profiler.start diff --git a/test/test_helper.rb b/test/test_helper.rb index 75d54911..e56efee3 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -12,6 +12,7 @@ if env_mode = ENV['LIQUID_PARSER_MODE'] mode = env_mode.to_sym end Liquid::Template.error_mode = mode +Liquid::Profiler.load_hooks if Minitest.const_defined?('Test') # We're on Minitest 5+. Nothing to do here.