Sha256: 06d90b46207d43ad3b13b46782bb29a75f742d1361aac7283e3f8a7be1b550d4

Contents?: true

Size: 458 Bytes

Versions: 12

Compression:

Stored size: 458 Bytes

Contents

module MongoModel
  module Types
    class Integer < Object
      def cast(value)
        if value.nil?
          nil
        else
          begin
            Kernel::Integer(value)
          rescue ArgumentError
            Kernel::Float(value).to_i rescue nil
          end
        end
      end
      
      def boolean(value)
        !value.zero?
      end
    end
  end
end

MongoModel::Types.register_converter(Integer, MongoModel::Types::Integer.new)

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
mongomodel-0.5.5 lib/mongomodel/support/types/integer.rb
mongomodel-0.5.4 lib/mongomodel/support/types/integer.rb
mongomodel-0.5.3 lib/mongomodel/support/types/integer.rb
mongomodel-0.5.2 lib/mongomodel/support/types/integer.rb
mongomodel-0.5.1 lib/mongomodel/support/types/integer.rb
mongomodel-0.5.0 lib/mongomodel/support/types/integer.rb
mongomodel-0.4.9 lib/mongomodel/support/types/integer.rb
mongomodel-0.4.8 lib/mongomodel/support/types/integer.rb
mongomodel-0.4.7 lib/mongomodel/support/types/integer.rb
mongomodel-0.4.6 lib/mongomodel/support/types/integer.rb
mongomodel-0.4.5 lib/mongomodel/support/types/integer.rb
mongomodel-0.4.4 lib/mongomodel/support/types/integer.rb