Sha256: acf6b3d857a1e675801d41558e6761cebdde660a37297e8f9aae81a04fb93916

Contents?: true

Size: 638 Bytes

Versions: 4

Compression:

Stored size: 638 Bytes

Contents

module EnumHelp
  module I18n

    # overwrite the enum method
    def enum( definitions )
      klass = self
      super( definitions )
      definitions.each do |name, values|
        # def status_i18n() statuses.key self[:status] end
        i18n_method_name = "#{name}_i18n".to_sym
        define_method(i18n_method_name) do
          enum_value = self.send(name)
          ::I18n.t("enums.#{klass.to_s.downcase}.#{name}.#{enum_value}", default: enum_value)
        end
      end
    end


    def self.extended(receiver)
      # receiver.class_eval do
      #   # alias_method_chain :enum, :enum_help
      # end
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
enum_help-0.0.4 lib/enum_help/i18n.rb
enum_help-0.0.3 lib/enum_help/i18n.rb
enum_help-0.0.2 lib/enum_help/i18n.rb
enum_help-0.0.1 lib/enum_help/i18n.rb