Sha256: e0512585cfb5fb2e8e1b2ef35f0cd3af0cd09cba2417c29fa9bfd2b32d4ead3b

Contents?: true

Size: 940 Bytes

Versions: 1

Compression:

Stored size: 940 Bytes

Contents

require 'rails_admin/config/fields/types/enum'

module RailsAdmin
  module Config
    module Fields
      module Types
        class ActiveRecordEnum < Enum
          RailsAdmin::Config::Fields::Types.register(self)

          def type
            :enum
          end

          register_instance_option :enum do
            abstract_model.model.defined_enums[name.to_s]
          end

          register_instance_option :pretty_value do
            bindings[:object].send(name).presence || ' - '
          end

          register_instance_option :multiple? do
            false
          end

          register_instance_option :queryable do
            false
          end

          def parse_value(value)
            value.present? ? enum.invert[value.to_i] : nil
          end

          def parse_input(params)
            params[name] = parse_value(params[name]) if params[name]
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rails_admin-0.8.1 lib/rails_admin/config/fields/types/active_record_enum.rb