Class: Liquid::Strainer
- Inherits:
-
Object
- Object
- Liquid::Strainer
- Defined in:
- lib/liquid/strainer.rb
Overview
Strainer is the parent class for the filters system. New filters are mixed into the strainer class which is then instanciated for each liquid template render run.
One of the strainer’s responsibilities is to keep malicious method calls out
Constant Summary collapse
- INTERNAL_METHOD =
:nodoc:
/^__/
- @@required_methods =
Set.new([:__id__, :__send__, :respond_to?, :extend, :methods, :class, :object_id])
- @@filters =
{}
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(context) ⇒ Strainer
constructor
A new instance of Strainer.
- #respond_to?(method, include_private = false) ⇒ Boolean
Constructor Details
#initialize(context) ⇒ Strainer
Returns a new instance of Strainer.
21 22 23 |
# File 'lib/liquid/strainer.rb', line 21 def initialize(context) @context = context end |
Class Method Details
.create(context) ⇒ Object
30 31 32 33 34 |
# File 'lib/liquid/strainer.rb', line 30 def self.create(context) strainer = Strainer.new(context) @@filters.each { |k,m| strainer.extend(m) } strainer end |
.global_filter(filter) ⇒ Object
25 26 27 28 |
# File 'lib/liquid/strainer.rb', line 25 def self.global_filter(filter) raise ArgumentError, "Passed filter is not a module" unless filter.is_a?(Module) @@filters[filter.name] = filter end |
Instance Method Details
#respond_to?(method, include_private = false) ⇒ Boolean
36 37 38 39 40 41 |
# File 'lib/liquid/strainer.rb', line 36 def respond_to?(method, include_private = false) method_name = method.to_s return false if method_name =~ INTERNAL_METHOD return false if @@required_methods.include?(method_name) super end |