Sha256: 9ffecd6366c9739200963fceecb7945d03198bcacca7251bfe1704acb6d7c471

Contents?: true

Size: 526 Bytes

Versions: 2

Compression:

Stored size: 526 Bytes

Contents

module Para
  module AttributeField
    class EnumField < AttributeField::Base
      register :enum, self

      def value_for(instance)
        if (raw_value = instance.send(name)) &&
          path = enum_path_for(instance, raw_value)
          translation = I18n.t("activerecord.#{ path }", default: false)

          translation || raw_value
        end
      end

      private

      def enum_path_for(instance, key)
        ['enums', instance.class.model_name.i18n_key, name, key].join('.')
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
para-0.5.1 lib/para/attribute_field/enum.rb
para-0.5.0 lib/para/attribute_field/enum.rb