Module: Enumlingo
- Defined in:
- lib/enumlingo.rb,
lib/enumlingo/helper.rb,
lib/enumlingo/railtie.rb,
lib/enumlingo/version.rb
Defined Under Namespace
Classes: Railtie
Constant Summary collapse
- VERSION =
"0.2.0"
Instance Method Summary collapse
Instance Method Details
#enumlingo(*attributes) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/enumlingo/helper.rb', line 2 def enumlingo(*attributes) attributes.each do |attribute| pluralized_attribute = attribute.to_s.pluralize define_method "#{attribute}_lingo" do |locale: I18n.locale| value = send(attribute) # return nil if value.nil? I18n.t("activerecord.attributes.#{model_name.i18n_key}.#{pluralized_attribute}.#{value}", locale: locale) end define_singleton_method "#{pluralized_attribute}_lingo" do |locale: I18n.locale| send(attribute.to_s.pluralize).map do |key, value| [I18n.t("activerecord.attributes.#{model_name.i18n_key}.#{pluralized_attribute}.#{key}", locale: locale), key] end end define_singleton_method "#{attribute}_lingo" do |key, locale: I18n.locale| I18n.t("activerecord.attributes.#{model_name.i18n_key}.#{pluralized_attribute}.#{key}", locale: locale) end define_singleton_method "#{pluralized_attribute}_lingo_values" do |locale: I18n.locale| send(attribute.to_s.pluralize).map do |key, value| [I18n.t("activerecord.attributes.#{model_name.i18n_key}.#{pluralized_attribute}.#{key}", locale: locale), value] end end end end |