Sha256: c86aa8c8f11e169cf55ae662dc1cacb9828d8d910b504500a36258eedc5166ff

Contents?: true

Size: 640 Bytes

Versions: 2

Compression:

Stored size: 640 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.underscore}.#{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

2 entries across 2 versions & 1 rubygems

Version Path
enum_help-0.0.6 lib/enum_help/i18n.rb
enum_help-0.0.5 lib/enum_help/i18n.rb