Add a class cache to avoid runtime extend calls

* Strainer has a class cache that creates Strainer subclasses for each filter
   set that is used on .create calls.
 * Context now creates a list of filters and passes this to Strainer.create to
   utilize the class cache in almost all use cases.
 * If add_filter was called after a render, then the method cache may still be
   invalidated.

Conflicts:

	lib/liquid/strainer.rb
This commit is contained in:
James Tucker
2013-08-31 18:56:35 +00:00
parent e8b41c8856
commit 9b2d5b7dd3
3 changed files with 36 additions and 7 deletions
+11
View File
@@ -49,4 +49,15 @@ class StrainerTest < Test::Unit::TestCase
assert_equal "has_method?", strainer.invoke("invoke", "has_method?", "invoke")
end
def test_strainer_uses_a_class_cache_to_avoid_method_cache_invalidation
a, b = Module.new, Module.new
strainer = Strainer.create(nil, [a,b])
assert_kind_of Strainer, strainer
assert_kind_of a, strainer
assert_kind_of b, strainer
Strainer.class_variable_get(:@@filters).values.each do |m|
assert_kind_of m, strainer
end
end
end # StrainerTest