Class: ActiveEnum::Storage::I18nStore

Inherits:
MemoryStore show all
Defined in:
lib/active_enum/storage/i18n_store.rb

Instance Method Summary collapse

Methods inherited from MemoryStore

#_values, #set, #sort!

Methods inherited from AbstractStore

#check_duplicate, #initialize, #set

Constructor Details

This class inherits a constructor from ActiveEnum::Storage::AbstractStore

Instance Method Details

#get_by_id(id) ⇒ Object



6
7
8
9
# File 'lib/active_enum/storage/i18n_store.rb', line 6

def get_by_id(id)
  row = _values.assoc(id)
  [ id, translate(row[1]), row[2] ].compact if row
end

#get_by_name(name) ⇒ Object



11
12
13
14
# File 'lib/active_enum/storage/i18n_store.rb', line 11

def get_by_name(name)
  row = _values.rassoc(name.to_s)
  [ row[0], translate(row[1]), row[2] ].compact if row
end

#i18n_scopeObject



20
21
22
# File 'lib/active_enum/storage/i18n_store.rb', line 20

def i18n_scope
  @i18n_scope ||= [ :active_enum ] + @enum.name.split("::").map { |nesting| nesting.underscore.to_sym }
end

#translate(key) ⇒ Object



24
25
26
# File 'lib/active_enum/storage/i18n_store.rb', line 24

def translate(key)
  I18n.translate key, scope: i18n_scope, default: key
end

#valuesObject



16
17
18
# File 'lib/active_enum/storage/i18n_store.rb', line 16

def values
  _values.map { |(id, _)| get_by_id(id) }
end