Sha256: 6d47b88b8d0abfad6fc9a83bcadcd1d82ca6085ee5f6c5efa072ce192dd9a747

Contents?: true

Size: 1.35 KB

Versions: 26

Compression:

Stored size: 1.35 KB

Contents

require 'rails_admin/config/fields/types/string'

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

          register_instance_option :partial do
            :form_enumeration
          end

          register_instance_option :enum_method do
            @enum_method ||= bindings[:object].class.respond_to?("#{name}_enum") || bindings[:object].respond_to?("#{name}_enum") ? "#{name}_enum" : name
          end

          register_instance_option :enum do
            bindings[:object].class.respond_to?(enum_method) ? bindings[:object].class.send(enum_method) : bindings[:object].send(enum_method)
          end

          register_instance_option :pretty_value do
            if enum.is_a?(::Hash)
              enum.reject { |_k, v| v.to_s != value.to_s }.keys.first.to_s.presence || value.presence || ' - '
            elsif enum.is_a?(::Array) && enum.first.is_a?(::Array)
              enum.detect { |e| e[1].to_s == value.to_s }.try(:first).to_s.presence || value.presence || ' - '
            else
              value.presence || ' - '
            end
          end

          register_instance_option :multiple? do
            properties && [:serialized].include?(properties.type)
          end
        end
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 2 rubygems

Version Path
rails_admin-2.3.1 lib/rails_admin/config/fields/types/enum.rb
rails_admin-2.3.0 lib/rails_admin/config/fields/types/enum.rb
rails_admin-2.2.1 lib/rails_admin/config/fields/types/enum.rb
rails_admin-2.2.0 lib/rails_admin/config/fields/types/enum.rb
rails_admin-2.1.1 lib/rails_admin/config/fields/types/enum.rb
rails_admin-2.1.0 lib/rails_admin/config/fields/types/enum.rb
rails_admin-2.0.2 lib/rails_admin/config/fields/types/enum.rb
rails_admin-1.4.3 lib/rails_admin/config/fields/types/enum.rb
rails_admin-2.0.1 lib/rails_admin/config/fields/types/enum.rb
rails_admin-2.0.0 lib/rails_admin/config/fields/types/enum.rb
rails_admin-2.0.0.rc lib/rails_admin/config/fields/types/enum.rb
rails_admin-2.0.0.beta lib/rails_admin/config/fields/types/enum.rb
rails_admin-1.4.2 lib/rails_admin/config/fields/types/enum.rb
rails_admin-1.4.1 lib/rails_admin/config/fields/types/enum.rb
rails_admin-1.4.0 lib/rails_admin/config/fields/types/enum.rb
rails_admin-1.3.0 lib/rails_admin/config/fields/types/enum.rb
rails_admin-1.2.0 lib/rails_admin/config/fields/types/enum.rb
rails_admin-1.1.1 lib/rails_admin/config/fields/types/enum.rb
rails_admin-1.1.0 lib/rails_admin/config/fields/types/enum.rb
rails_admin-1.0.0 lib/rails_admin/config/fields/types/enum.rb