Sha256: b52618de52d97a102941edd9226d0f5ccc99d511bf85148e54cb432aeb0332f5

Contents?: true

Size: 554 Bytes

Versions: 33

Compression:

Stored size: 554 Bytes

Contents

$LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
require 'mongo_mapper'
require 'pp'

MongoMapper.database = 'testing'

class DowncasedString
  # to_mongo gets called anytime a value is assigned
  def self.to_mongo(value)
    value.nil? ? nil : value.to_s.downcase
  end

  # from mongo gets called anytime a value is read
  def self.from_mongo(value)
    value.nil? ? nil : value.to_s.downcase
  end
end

class User
  include MongoMapper::Document
  key :email, DowncasedString
end

pp User.create(:email => 'IDontLowerCaseThings@gmail.com')

Version data entries

33 entries across 33 versions & 7 rubygems

Version Path
mongo_mapper-0.16.0 examples/custom_types.rb
mongo_mapper-0.15.6 examples/custom_types.rb
mongo_mapper-0.15.5 examples/custom_types.rb
mongo_mapper-0.15.4 examples/custom_types.rb
mongo_mapper-0.15.3 examples/custom_types.rb
mongo_mapper-0.15.2 examples/custom_types.rb
mongo_mapper-0.15.1 examples/custom_types.rb
mongo_mapper-0.15.0 examples/custom_types.rb
mongo_mapper-0.14.0 examples/custom_types.rb
mongo_mapper-0.14.0.rc1 examples/custom_types.rb
mongo_mapper-0.13.1 examples/custom_types.rb
mongo_mapper-0.13.0 examples/custom_types.rb
mongo_mapper-0.13.0.beta2 examples/custom_types.rb
mongo_mapper-0.13.0.beta1 examples/custom_types.rb
mongo_mapper-0.12.0 examples/custom_types.rb
lookout-mongo_mapper-0.11.3 examples/custom_types.rb
mongo_mapper-0.11.2 examples/custom_types.rb
jamieorc-mongo_mapper-0.11.1.1 examples/custom_types.rb
mongo_mapper-0.11.1 examples/custom_types.rb
mongo_mapper-0.11.0 examples/custom_types.rb