Sha256: ce4f6b86bd50a5015129e0ec78850421c2aaba1a655447b087af14957f5c637b

Contents?: true

Size: 922 Bytes

Versions: 10

Compression:

Stored size: 922 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; end unless defined?(Boolean)

Boolean.extend MongoMapper::Extensions::Boolean

Version data entries

10 entries across 10 versions & 3 rubygems

Version Path
mongo_mapper-0.12.0 lib/mongo_mapper/extensions/boolean.rb
lookout-mongo_mapper-0.11.3 lib/mongo_mapper/extensions/boolean.rb
mongo_mapper-0.11.2 lib/mongo_mapper/extensions/boolean.rb
jamieorc-mongo_mapper-0.11.1.1 lib/mongo_mapper/extensions/boolean.rb
mongo_mapper-0.11.1 lib/mongo_mapper/extensions/boolean.rb
mongo_mapper-0.11.0 lib/mongo_mapper/extensions/boolean.rb
mongo_mapper-0.10.1 lib/mongo_mapper/extensions/boolean.rb
mongo_mapper-0.10.0 lib/mongo_mapper/extensions/boolean.rb
mongo_mapper-0.9.2 lib/mongo_mapper/extensions/boolean.rb
mongo_mapper-0.9.1 lib/mongo_mapper/extensions/boolean.rb