Sha256: 4148b1fef851d10c222c761846af7202af2bce8bc9fe03e721d69901f4c2b02a

Contents?: true

Size: 1.06 KB

Versions: 3

Compression:

Stored size: 1.06 KB

Contents

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

module RailsAdmin
  module Config
    module Fields
      module Types
        class BsonObjectId < RailsAdmin::Config::Fields::Types::String
          # Register field type for the type loader
          RailsAdmin::Config::Fields::Types::register(self)

          register_instance_option(:label) do
            label = ((@label ||= {})[::I18n.locale] ||= abstract_model.model.human_attribute_name name)
            label = "_id" if label == ''
            label
          end

          register_instance_option(:help) do
            "BSON::ObjectId"
          end

          register_instance_option(:read_only) do
            true
          end

          register_instance_option(:visible?) do
            @name.to_s != '_id'
          end

          def parse_input(params)
            begin
              params[name] = (params[name].blank? ? nil : BSON::ObjectId(params[name])) if params[name].is_a?(::String)
            rescue BSON::InvalidObjectId
            end
          end
        end
      end
    end
  end
end



Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
obitum-rails_admin-0.0.5 lib/rails_admin/config/fields/types/bson_object_id.rb
drewda_rails_admin-0.0.1 lib/rails_admin/config/fields/types/bson_object_id.rb
obitum-rails_admin-0.0.4 lib/rails_admin/config/fields/types/bson_object_id.rb