Sha256: ce2aeaf80f4be53a825334301cc6c24dc996da3f1727604f77ca4ccbb8e34ce8

Contents?: true

Size: 888 Bytes

Versions: 61

Compression:

Stored size: 888 Bytes

Contents

# encoding: UTF-8
module MongoMapper
  module Extensions
    module Boolean
      Mapping = {
        true    => true, 
        'true'  => true, 
        'TRUE'  => true, 
        'True'  => true, 
        't'     => true, 
        'T'     => true, 
        '1'     => true, 
        1       => true, 
        1.0     => true,
        false   => false, 
        'false' => false, 
        'FALSE' => false, 
        'False' => false, 
        'f'     => false, 
        'F'     => false, 
        '0'     => false, 
        0       => false, 
        0.0     => false, 
        nil     => nil
      }

      def to_mongo(value)
        if value.is_a?(Boolean)
          value
        else
          Mapping[value]
        end
      end

      def from_mongo(value)
        value.nil? ? nil : !!value
      end
    end
  end
end

class Boolean
  extend MongoMapper::Extensions::Boolean
end

Version data entries

61 entries across 61 versions & 7 rubygems

Version Path
jonbell-mongo_mapper-0.8.6 lib/mongo_mapper/extensions/boolean.rb
mongo_mapper-0.9.0 lib/mongo_mapper/extensions/boolean.rb
ign-mongo_mapper-0.8.6.2 lib/mongo_mapper/extensions/boolean.rb
ign-mongo_mapper-0.8.6.1 lib/mongo_mapper/extensions/boolean.rb
ssherman-mongo_mapper-0.8.6 lib/mongo_mapper/extensions/boolean.rb
mongo_mapper-0.8.6 lib/mongo_mapper/extensions/boolean.rb
mongo_mapper-0.8.5 lib/mongo_mapper/extensions/boolean.rb
honkster-mongo_mapper-0.8.4 lib/mongo_mapper/extensions/boolean.rb
mongo_mapper-0.8.4 lib/mongo_mapper/extensions/boolean.rb
mongo_mapper-unstable-2010.08.19 lib/mongo_mapper/extensions/boolean.rb
mongo_mapper-unstable-2010.08.18 lib/mongo_mapper/extensions/boolean.rb
mongo_mapper-unstable-2010.08.17 lib/mongo_mapper/extensions/boolean.rb
mongo_mapper-unstable-2010.08.16 lib/mongo_mapper/extensions/boolean.rb
mongo_mapper-unstable-2010.08.15 lib/mongo_mapper/extensions/boolean.rb
mongo_mapper-unstable-2010.08.14 lib/mongo_mapper/extensions/boolean.rb
mongo_mapper-unstable-2010.08.13 lib/mongo_mapper/extensions/boolean.rb
mongo_mapper-unstable-2010.08.12 lib/mongo_mapper/extensions/boolean.rb
mongo_mapper-unstable-2010.08.11 lib/mongo_mapper/extensions/boolean.rb
mongo_mapper-unstable-2010.08.10 lib/mongo_mapper/extensions/boolean.rb
mongo_mapper-unstable-2010.08.09 lib/mongo_mapper/extensions/boolean.rb