Module: EnumTranslate
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/enum_translate/errors.rb,
lib/enum_translate/version.rb,
lib/enum_translate/enum_translate_concern.rb
Defined Under Namespace
Modules: ClassMethods Classes: EnumTranslateArgumentError, EnumTranslateError
Constant Summary collapse
- VERSION =
"0.1.0"
Instance Method Summary collapse
Instance Method Details
#human_attribute_text(attribute_name) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/enum_translate/enum_translate_concern.rb', line 8 def human_attribute_text(attribute_name) attribute_value = public_send(attribute_name) # `attribute_value` is a return value of calling ActiveRecord::Enum attribute instance API. # It should be a String value, and raise an error if not. raise EnumTranslateArgumentError, "#{self.class.name.underscore}.#{attribute_name} should be String value." unless attribute_value.is_a?(String) I18n.t "activerecord.attributes.#{self.class.name.underscore}/#{attribute_name}.#{attribute_value}", default: attribute_value end |