class R18n::FilterList

Superclass for `GlobalFilterList` and `CustomFilterList` with filters processing.

Public Instance Methods

active(_type) click to toggle source

List of enable active filters.

# File lib/r18n-core/filter_list.rb, line 85
def active(_type)
  []
end
all(_type) click to toggle source

List of enable filters.

# File lib/r18n-core/filter_list.rb, line 90
def all(_type)
  []
end
enabled(filters_type, type) click to toggle source

`Array` of enabled filters with `filters_type` for `type`.

# File lib/r18n-core/filter_list.rb, line 68
def enabled(filters_type, type)
  case filters_type
  when :passive
    passive(type)
  when :active
    active(type)
  else
    all(type)
  end
end
passive(_type) click to toggle source

List of enable passive filters.

# File lib/r18n-core/filter_list.rb, line 80
def passive(_type)
  []
end
process(filters_type, type, value, locale, path, params) click to toggle source

Process `value` by filters in `enabled`.

# 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) click to toggle source

Process `value` by global filters in `enabled`.

# File lib/r18n-core/filter_list.rb, line 53
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.instance_of? String
    TranslatedString.new(value, config[:locale], config[:path], self)
  else
    value
  end
end
process_typed(filters_type, typed_value, params) click to toggle source

Shortcut to process `R18n::Typed`.

# 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