Sha256: 5f0d3c02a79219dd0bdd04b4c03913bd25d6f6e7e44946c36b74b026bab03192
Contents?: true
Size: 833 Bytes
Versions: 1
Compression:
Stored size: 833 Bytes
Contents
require 'i18n' module ActiveEnum module Storage class I18nStore < MemoryStore def get_by_id(id) row = _values.assoc(id) [ id, translate(row[1]), row[2] ].compact if row end def get_by_name(name) row = _values.rassoc(name.to_s) [ row[0], translate(row[1]), row[2] ].compact if row end def values _values.map { |(id, name)| get_by_id(id) } end def check_duplicate(id, name) if _values.assoc(id) || _values.rassoc(name.to_s) raise ActiveEnum::DuplicateValue end end def i18n_scope @i18n_scope ||= [ :active_enum ] + @enum.name.split("::").map { |nesting| nesting.underscore.to_sym } end def translate(key) I18n.translate key, :scope => i18n_scope end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
active_enum-0.9.10 | lib/active_enum/storage/i18n_store.rb |