Sha256: d37208697f569f8990f4407343d9197df063a32e4d170e4ea5a40f6c2242ddb6

Contents?: true

Size: 615 Bytes

Versions: 17

Compression:

Stored size: 615 Bytes

Contents

# frozen_string_literal: true

module Mongoid
  class Boolean

    class << self

      # Turn the object from the ruby type we deal with to a Mongo friendly
      # type.
      #
      # @example Mongoize the object.
      #   Boolean.mongoize("123.11")
      #
      # @return [ true | false | nil ] The object mongoized or nil.
      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
      alias :demongoize :mongoize
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
mongoid-8.1.8 lib/mongoid/extensions/boolean.rb
mongoid-8.1.7 lib/mongoid/extensions/boolean.rb
mongoid-8.1.6 lib/mongoid/extensions/boolean.rb
mongoid-8.0.8 lib/mongoid/extensions/boolean.rb
mongoid-8.1.5 lib/mongoid/extensions/boolean.rb
mongoid-8.1.4 lib/mongoid/extensions/boolean.rb
mongoid-8.0.7 lib/mongoid/extensions/boolean.rb
mongoid-8.1.3 lib/mongoid/extensions/boolean.rb
mongoid-8.1.2 lib/mongoid/extensions/boolean.rb
mongoid-8.0.6 lib/mongoid/extensions/boolean.rb
mongoid-8.1.1 lib/mongoid/extensions/boolean.rb
mongoid-8.0.5 lib/mongoid/extensions/boolean.rb
mongoid-8.1.0 lib/mongoid/extensions/boolean.rb
mongoid-8.0.4 lib/mongoid/extensions/boolean.rb
mongoid-8.0.3 lib/mongoid/extensions/boolean.rb
mongoid-8.0.2 lib/mongoid/extensions/boolean.rb
mongoid-8.0.1 lib/mongoid/extensions/boolean.rb