Class: R18n::CustomFilterList
Overview
Filter list for I18n object with custom disabled/enabled filters.
Instance Method Summary
collapse
Methods inherited from FilterList
#enabled, #process, #process_string, #process_typed
Constructor Details
Returns a new instance of CustomFilterList.
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
# File 'lib/r18n-core/filter_list.rb', line 114
def initialize(on, off)
@on = Array(on).map { |i| Filters.defined[i] }
@off = Array(off).map { |i| Filters.defined[i] }
@changed_types = (@on + @off).map { |i| i.types }.flatten.uniq
@changed_passive = (@on + @off).reject { |i| !i.passive? }.
map { |i| i.types }.flatten.uniq
@changed_active = (@on + @off).reject { |i| i.passive? }.
map { |i| i.types }.flatten.uniq
@on_by_type = {}
@on.each do |filter|
filter.types.each do |type|
@on_by_type[type] ||= []
@on_by_type[type] << filter
end
end
@off_by_type = {}
@off.each do |filter|
filter.types.each do |type|
@off_by_type[type] ||= []
@off_by_type[type] << filter
end
end
end
|
Instance Method Details
#active(type) ⇒ Object
147
148
149
150
151
152
|
# File 'lib/r18n-core/filter_list.rb', line 147
def active(type)
enabled = Filters.active_enabled[type]
return enabled unless @changed_active.include? type
enabled = enabled.reject { |i| @off_by_type[type].include? i }
enabled += @on_by_type[type].reject { |i| i.passive }
end
|
#all(type) ⇒ Object
154
155
156
157
158
159
|
# File 'lib/r18n-core/filter_list.rb', line 154
def all(type)
enabled = Filters.enabled[type]
return enabled unless @changed_types.include? type
enabled = enabled.reject { |i| @off_by_type[type].include? i }
enabled += @on_by_type[type]
end
|
#hash ⇒ Object
161
162
163
|
# File 'lib/r18n-core/filter_list.rb', line 161
def hash
[@on, @off].hash
end
|
#passive(type) ⇒ Object
140
141
142
143
144
145
|
# File 'lib/r18n-core/filter_list.rb', line 140
def passive(type)
enabled = Filters.passive_enabled[type]
return enabled unless @changed_passive.include? type
enabled = enabled.reject { |i| @off_by_type[type].include? i }
enabled += @on_by_type[type].reject { |i| !i.passive }
end
|