Class: Administrate::Field::I18nEnum

Inherits:
Select
  • Object
show all
Defined in:
lib/administrate/field/i18n_enum.rb

Defined Under Namespace

Classes: Engine

Instance Method Summary collapse

Instance Method Details

#class_nameObject



18
19
20
# File 'lib/administrate/field/i18n_enum.rb', line 18

def class_name
  @options.fetch(:class_name, '').camelcase.downcase
end

#enum_optionsObject



10
11
12
13
14
15
16
# File 'lib/administrate/field/i18n_enum.rb', line 10

def enum_options
  enums = collection.map do |k, v|
    [translate(class_name, @attribute, k), k]
  end
  enums.unshift(['', nil]) if @options.fetch(:null, false) == true
  enums
end

#translate(class_name, attribute, value) ⇒ Object



22
23
24
# File 'lib/administrate/field/i18n_enum.rb', line 22

def translate(class_name, attribute, value)
  I18n.t("#{class_name}.#{attribute}.#{value}", scope: @options.fetch(:scope, nil), default: value)
end