Sha256: 8a4647342cc22d9e625b16786e1c53c0d6de4207b16ad58e629d6a143a6ff3f6

Contents?: true

Size: 1.13 KB

Versions: 10

Compression:

Stored size: 1.13 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

          def generic_help
            'BSON::ObjectId'
          end

          register_instance_option :read_only do
            true
          end

          register_instance_option :sort_reverse? do
            serial?
          end

          def parse_input(params)
            params[name] = (params[name].blank? ? nil : abstract_model.object_id_from_string(params[name])) if params[name].is_a?(::String)
          rescue => e
            unless ['BSON::InvalidObjectId', 'Moped::Errors::InvalidObjectId'].include? e.class.to_s
              raise e
            end
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
sc_core-0.0.7 test/dummy/vendor/bundle/ruby/2.2.0/gems/rails_admin-0.7.0/lib/rails_admin/config/fields/types/bson_object_id.rb
rails_admin-0.7.0 lib/rails_admin/config/fields/types/bson_object_id.rb
rails_admin-0.6.8 lib/rails_admin/config/fields/types/bson_object_id.rb
rails_admin-0.6.7 lib/rails_admin/config/fields/types/bson_object_id.rb
rails_admin-0.6.6 lib/rails_admin/config/fields/types/bson_object_id.rb
rails_admin-0.6.5 lib/rails_admin/config/fields/types/bson_object_id.rb
rails_admin-0.6.4 lib/rails_admin/config/fields/types/bson_object_id.rb
rails_admin-0.6.3 lib/rails_admin/config/fields/types/bson_object_id.rb
rails_admin-0.6.2 lib/rails_admin/config/fields/types/bson_object_id.rb
rails_admin-0.6.1 lib/rails_admin/config/fields/types/bson_object_id.rb