123456789_123456789_123456789_123456789_123456789_

Class: Mongoid::Boolean

Relationships & Source Files
Inherits: Object
Defined in: lib/mongoid/extensions/boolean.rb

Overview

Adds type-casting behavior to Boolean class.

Class Method Summary

Class Method Details

.demongoize(object)

Alias for .mongoize.

[ GitHub ]

  
# File 'lib/mongoid/extensions/boolean.rb', line 26

alias :demongoize :mongoize

.mongoize(object) ⇒ true | false | nil Also known as: .demongoize

Turn the object from the ruby type we deal with to a Mongo friendly type.

Examples:

Mongoize the object.

Boolean.mongoize("123.11")

Returns:

  • (true | false | nil)

    The object mongoized or nil.

[ GitHub ]

  
# File 'lib/mongoid/extensions/boolean.rb', line 18

def mongoize(object)
  return if object.nil?
  if object.to_s =~ (/\A(true|t|yes|y|on|1|1.0)\z/i)
    true
  elsif object.to_s =~ (/\A(false|f|no|n|off|0|0.0)\z/i)
    false
  end
end