Class: SelectableAttr::Enum

Inherits:
Object
  • Object
show all
Defined in:
lib/selectable_attr_i18n.rb

Class Method Summary collapse

Class Method Details

.i18n_export(enums = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/selectable_attr_i18n.rb', line 6

def self.i18n_export(enums = nil)
  enums ||= instances
  result = {}
  enums.each do |instance|
    unless instance.i18n_scope
      SelectableAttrRails.logger.debug("no i18n_scope of #{instance.inspect}")
      next
    end
    paths = instance.i18n_scope.dup
    current = result
    paths.each do |path|
      current = current[path.to_s] ||= {}
    end
    instance.entries.each do |entry|
      current[entry.key.to_s] = entry.name
    end
  end
  result
end