module MongoMapper::Extensions::Array::ClassMethods

Public Instance Methods

from_mongo(value) click to toggle source
# File lib/mongo_mapper/extensions/array.rb, line 32
def from_mongo(value)
  value || []
end
to_mongo(value, options = {}) click to toggle source
# File lib/mongo_mapper/extensions/array.rb, line 10
def to_mongo(value, options = {})
  stringify_bson = options[:stringify_bson]
  recursive      = options[:recursive]

  value = value.clone if recursive
  value = value.respond_to?(:lines) ? value.lines : value
  value = value.to_a
  value.map! do |v|
    
    case v
    when Document, EmbeddedDocument, Hash, Array, Set
      v = v.to_mongo(options) if v and recursive
    when BSON::ObjectId, BSON::Binary
      v = v.to_s if stringify_bson
    end
    
    v
    
  end
  value
end