Sha256: ce0692446c4cc12885b4bda578eb55828fd07d5f2c78cfa4c77e27c6a6387341

Contents?: true

Size: 579 Bytes

Versions: 54

Compression:

Stored size: 579 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: '')

          translation.presence || raw_value
        end
      end

      def field_type
        :selectize
      end

      private

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

Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
para-0.12.4 lib/para/attribute_field/enum.rb
para-0.12.3 lib/para/attribute_field/enum.rb
para-0.12.2 lib/para/attribute_field/enum.rb
para-0.12.1 lib/para/attribute_field/enum.rb
para-0.12.0 lib/para/attribute_field/enum.rb
para-0.11.4 lib/para/attribute_field/enum.rb
para-0.11.3 lib/para/attribute_field/enum.rb
para-0.11.2 lib/para/attribute_field/enum.rb
para-0.11.1 lib/para/attribute_field/enum.rb
para-0.11.0 lib/para/attribute_field/enum.rb
para-0.10.0 lib/para/attribute_field/enum.rb
para-0.9.4 lib/para/attribute_field/enum.rb
para-0.9.3.3 lib/para/attribute_field/enum.rb
para-0.9.3.2 lib/para/attribute_field/enum.rb
para-0.9.3.1 lib/para/attribute_field/enum.rb
para-0.9.2 lib/para/attribute_field/enum.rb
para-0.9.0 lib/para/attribute_field/enum.rb
para-0.8.15 lib/para/attribute_field/enum.rb
para-0.8.14 lib/para/attribute_field/enum.rb
para-0.8.13 lib/para/attribute_field/enum.rb