Class: Liquid::Autoescape::ExemptionList
- Inherits:
-
Object
- Object
- Liquid::Autoescape::ExemptionList
- Defined in:
- lib/liquid/autoescape/exemption_list.rb
Overview
A list of exemptions that may apply to template variables
Exemption lists manage one or more exemptions, and determine whether any managed exemptions applies to a template variable. Exemptions can be added as individual filter functions, or can be imported in bulk from a module.
Class Method Summary collapse
-
.from_module(source) ⇒ Liquid::Autoescape::ExemptionList
Create an exemption list from a module’s instance methods.
Instance Method Summary collapse
-
#add(&filter) ⇒ Liquid::Autoescape::ExemptionList
Add a single filter function to use as an exemption.
-
#applies?(variable) ⇒ Boolean
(also: #apply?)
Determine whether any of the exemptions apply to a Liquid variable.
-
#import(source) ⇒ Liquid::Autoescape::ExemptionList
Add all instance methods of a module as exemptions.
-
#initialize ⇒ ExemptionList
constructor
Create a new exemption list.
-
#populated? ⇒ Boolean
Whether the exemption list has exemptions.
-
#size ⇒ Integer
The number of exemptions in the list.
Constructor Details
#initialize ⇒ ExemptionList
Create a new exemption list
48 49 50 |
# File 'lib/liquid/autoescape/exemption_list.rb', line 48 def initialize @exemptions = [] end |
Class Method Details
.from_module(source) ⇒ Liquid::Autoescape::ExemptionList
Create an exemption list from a module’s instance methods
41 42 43 44 45 |
# File 'lib/liquid/autoescape/exemption_list.rb', line 41 def self.from_module(source) exemptions = new exemptions.import(source) exemptions end |
Instance Method Details
#add(&filter) ⇒ Liquid::Autoescape::ExemptionList
Add a single filter function to use as an exemption
56 57 58 59 |
# File 'lib/liquid/autoescape/exemption_list.rb', line 56 def add(&filter) @exemptions << Exemption.new(&filter) self end |
#applies?(variable) ⇒ Boolean Also known as: apply?
Determine whether any of the exemptions apply to a Liquid variable
78 79 80 81 82 83 84 85 |
# File 'lib/liquid/autoescape/exemption_list.rb', line 78 def applies?(variable) @exemptions.each do |exemption| if exemption.applies?(variable) return true end end false end |
#import(source) ⇒ Liquid::Autoescape::ExemptionList
Add all instance methods of a module as exemptions
65 66 67 68 69 70 71 72 |
# File 'lib/liquid/autoescape/exemption_list.rb', line 65 def import(source) container = Module.new { extend source } exemptions = source.instance_methods(false) exemptions.each do |exemption| @exemptions << Exemption.new(&container.method(exemption)) end self end |
#populated? ⇒ Boolean
Whether the exemption list has exemptions
92 93 94 |
# File 'lib/liquid/autoescape/exemption_list.rb', line 92 def populated? !@exemptions.empty? end |
#size ⇒ Integer
The number of exemptions in the list
99 100 101 |
# File 'lib/liquid/autoescape/exemption_list.rb', line 99 def size @exemptions.size end |