Class: R18n::FilterList
- Inherits:
-
Object
- Object
- R18n::FilterList
- Defined in:
- lib/r18n-core/filter_list.rb
Overview
Superclass for GlobalFilterList
and CustomFilterList
with filters processing.
Direct Known Subclasses
Instance Method Summary collapse
-
#active(_type) ⇒ Object
List of enable active filters.
-
#all(_type) ⇒ Object
List of enable filters.
-
#enabled(filters_type, type) ⇒ Object
Array of enabled filters with
filters_type
fortype
. -
#passive(_type) ⇒ Object
List of enable passive filters.
-
#process(filters_type, type, value, locale, path, params) ⇒ Object
Process
value
by filters inenabled
. -
#process_string(filters_type, value, config, params) ⇒ Object
Process
value
by global filters inenabled
. -
#process_typed(filters_type, typed_value, params) ⇒ Object
Shortcut to process ‘R18n::Typed`.
Instance Method Details
#active(_type) ⇒ Object
List of enable active filters.
82 83 84 |
# File 'lib/r18n-core/filter_list.rb', line 82 def active(_type) [] end |
#all(_type) ⇒ Object
List of enable filters.
87 88 89 |
# File 'lib/r18n-core/filter_list.rb', line 87 def all(_type) [] end |
#enabled(filters_type, type) ⇒ Object
Array of enabled filters with filters_type
for type
.
66 67 68 69 70 71 72 73 74 |
# File 'lib/r18n-core/filter_list.rb', line 66 def enabled(filters_type, type) if filters_type == :passive passive(type) elsif filters_type == :active active(type) else all(type) end end |
#passive(_type) ⇒ Object
List of enable passive filters.
77 78 79 |
# File 'lib/r18n-core/filter_list.rb', line 77 def passive(_type) [] end |
#process(filters_type, type, value, locale, path, params) ⇒ Object
Process value
by filters in enabled
.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/r18n-core/filter_list.rb', line 25 def process(filters_type, type, value, locale, path, params) config = { locale: locale, path: path } enabled(filters_type, type).each do |filter| value = filter.call(value, config, *params) end if value.is_a? String value = TranslatedString.new(value, locale, path) process_string(filters_type, value, config, params) else value end end |
#process_string(filters_type, value, config, params) ⇒ Object
Process value
by global filters in enabled
.
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/r18n-core/filter_list.rb', line 51 def process_string(filters_type, value, config, params) config = { locale: value.locale, path: config } if config.is_a? String enabled(filters_type, String).each do |f| value = f.call(value, config, *params) end if value.class == String TranslatedString.new(value, config[:locale], config[:path], self) else value end end |
#process_typed(filters_type, typed_value, params) ⇒ Object
Shortcut to process ‘R18n::Typed`.
41 42 43 44 45 46 47 48 |
# File 'lib/r18n-core/filter_list.rb', line 41 def process_typed(filters_type, typed_value, params) process(filters_type, typed_value.type, typed_value.value, typed_value.locale, typed_value.path, params) end |