Class: R18n::FilterList

Inherits:
Object
  • Object
show all
Defined in:
lib/r18n-core/filter_list.rb

Overview

Superclass for GlobalFilterList and CustomFilterList with filters processing.

Direct Known Subclasses

CustomFilterList, GlobalFilterList

Instance Method Summary collapse

Instance Method Details

#active(type) ⇒ Object

List of enable active filters.



79
80
81
# File 'lib/r18n-core/filter_list.rb', line 79

def active(type)
  []
end

#all(type) ⇒ Object

List of enable filters.



84
85
86
# File 'lib/r18n-core/filter_list.rb', line 84

def all(type)
  []
end

#enabled(filters_type, type) ⇒ Object

Array of enabled filters with filters_type for type.



63
64
65
66
67
68
69
70
71
# File 'lib/r18n-core/filter_list.rb', line 63

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.



74
75
76
# File 'lib/r18n-core/filter_list.rb', line 74

def passive(type)
  []
end

#process(filters_type, type, value, locale, path, params) ⇒ Object

Process value by filters in enabled.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/r18n-core/filter_list.rb', line 26

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.



52
53
54
55
56
57
58
59
60
# File 'lib/r18n-core/filter_list.rb', line 52

def process_string(filters_type, value, config, params)
  if config.is_a? String
    config = { :locale => value.locale, :path => config }
  end
  enabled(filters_type, String).each do |f|
    value = f.call(value, config, *params)
  end
  value
end

#process_typed(filters_type, typed_value, params) ⇒ Object

Shortcut ot process ‘R18n::Typed`.



42
43
44
45
46
47
48
49
# File 'lib/r18n-core/filter_list.rb', line 42

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