Is there a better way to write this code? He currently creates a hash with the translation for its proper enums.
class ApplicationRecord < ActiveRecord::Base
def self.translate_enum(enum)
self.send(enum.to_s).map do |key, value|
{ self.human_enum_name(enum, key) => value }
end.reduce(:merge)
end
end
class EnumerableObject < ApplicationRecord
enum sales_exception: { without: 0, income: 1, commitment: 2, restriction: 3 }, _suffix: true
end
EnumerableObject.translate_enum(:sales_exception)
=> {"Sem Exceção"=>0, "Exceção Renda"=>1, "Exceção Comprometimento"=>2, "Exceção Restrição"=>3}