Class: Kongo::Collection

Inherits:
Object
  • Object
show all
Defined in:
lib/validate/kongo.rb

Instance Method Summary collapse

Instance Method Details

#validates?(hash) ⇒ Boolean

Returns whether ‘hash` would be a valid model if inserted.

Returns:

  • (Boolean)


14
15
16
17
18
19
20
# File 'lib/validate/kongo.rb', line 14

def validates?(hash)
  hash = hash.dup
  hash['_id'] = BSON::ObjectId.new unless hash.include?('_id')
  model = ::Kongo::Model.new(hash, coll)
  # NOTE: raises NoMethodError if the model does not have validations
  model.validates?
end