Module: Mongoid::Extensions::ObjectId::Conversions

Defined in:
lib/mongoid_integer_keys.rb

Overview

Override Mongoid::Extensions::ObjectId::Conversions.convert for covert id to Integer type.

Instance Method Summary collapse

Instance Method Details

#convert(klass, args, reject_blank = true) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/mongoid_integer_keys.rb', line 45

def convert(klass, args, reject_blank = true)
  case args
  when ::Array
    args.delete_if { |arg| arg.blank? } if reject_blank
    args.replace(args.map { |arg| convert(klass, arg, reject_blank) })
  when ::Hash
    args.tap do |hash|
      hash.each_pair do |key, value|
        hash[key] = value
      end
    end
  when ::Integer
    args
  else
    return nil if not args.to_s.match(/\d+/)
    args.to_i
  end
end