Class: Liquid::Strainer

Inherits:
Object
  • Object
show all
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?, :kind_of?, :extend, :methods, :singleton_methods, :class, :object_id])
@@filters =
{}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ Strainer

Returns a new instance of Strainer.



27
28
29
# File 'lib/liquid/strainer.rb', line 27

def initialize(context)
  @context = context
end

Class Method Details

.create(context) ⇒ Object



36
37
38
39
40
# File 'lib/liquid/strainer.rb', line 36

def self.create(context)
  strainer = Strainer.new(context)
  @@filters.each { |k,m| strainer.extend(m) }
  strainer
end

.global_filter(filter) ⇒ Object

Raises:



31
32
33
34
# File 'lib/liquid/strainer.rb', line 31

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

Returns:

  • (Boolean)


42
43
44
45
46
47
# File 'lib/liquid/strainer.rb', line 42

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