Class: R18n::Rails::Filters

Inherits:
Object
  • Object
show all
Defined in:
lib/r18n-rails/filters.rb

Overview

Load and remove filters from ruby files in ‘app/i18n`.

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.loadedObject

Path list of filters, which are loaded from app dir.



26
27
28
# File 'lib/r18n-rails/filters.rb', line 26

def loaded
  @loaded
end

.pathObject



30
31
32
33
34
# File 'lib/r18n-rails/filters.rb', line 30

def path
  return @path if defined?(@path)

  ::Rails.root.join('app/i18n')
end

Class Method Details

.load!Object

Load all ruby files from ‘app/i18n` and remember loaded filters.



37
38
39
40
41
# File 'lib/r18n-rails/filters.rb', line 37

def load!
  @loaded = R18n::Filters.listen do
    Pathname.glob(path.join('**/*.rb').to_s) { |i| load i.to_s; }
  end.map(&:name)
end

.reload!Object

Shortcut to call ‘remove!` and `load!`.



44
45
46
47
# File 'lib/r18n-rails/filters.rb', line 44

def reload!
  remove!
  load!
end

.remove!Object

Remove filters, loaded by ‘load!`.



50
51
52
53
# File 'lib/r18n-rails/filters.rb', line 50

def remove!
  @loaded.each { |i| R18n::Filters.delete(i) }
  @loaded = []
end