Module: Cadenza::Context::Filters
- Included in:
- Cadenza::Context
- Defined in:
- lib/cadenza/context/filters.rb
Instance Attribute Summary collapse
-
#filters ⇒ Hash
readonly
The filter names mapped to their implementing procs.
Instance Method Summary collapse
-
#alias_filter(original_name, alias_name) ⇒ Object
creates an alias of the given filter name under a different name.
-
#define_filter(name) {|String, *args| ... } ⇒ Object
defines a filter proc with the given name.
-
#evaluate_filter(name, input, params = []) ⇒ String
calls the defined filter proc with the given parameters and returns the result.
-
#lookup_filter(name) ⇒ Proc
looks up the filter by name.
Instance Attribute Details
#filters ⇒ Hash (readonly)
Returns the filter names mapped to their implementing procs.
10 11 12 |
# File 'lib/cadenza/context/filters.rb', line 10 def filters @filters ||= {} end |
Instance Method Details
#alias_filter(original_name, alias_name) ⇒ Object
creates an alias of the given filter name under a different name
40 41 42 |
# File 'lib/cadenza/context/filters.rb', line 40 def alias_filter(original_name, alias_name) define_filter alias_name, &lookup_filter(original_name) end |
#define_filter(name) {|String, *args| ... } ⇒ Object
defines a filter proc with the given name
29 30 31 32 |
# File 'lib/cadenza/context/filters.rb', line 29 def define_filter(name, &block) filters[name.to_sym] = block nil end |
#evaluate_filter(name, input, params = []) ⇒ String
calls the defined filter proc with the given parameters and returns the result.
53 54 55 |
# File 'lib/cadenza/context/filters.rb', line 53 def evaluate_filter(name, input, params=[]) lookup_filter(name).call(input, params) end |
#lookup_filter(name) ⇒ Proc
looks up the filter by name
19 20 21 |
# File 'lib/cadenza/context/filters.rb', line 19 def lookup_filter(name) filters.fetch(name.to_sym) { raise FilterNotDefinedError.new("undefined filter '#{name}'") } end |