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)


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

def validates?(hash)
  hash = hash.dup
  hash['_id'] = BSON::ObjectId.new unless hash.include?('_id')
  model = ::Kongo::Model.new(hash, coll)
  model.validates?
end

#validation_failures(hash) ⇒ Object

Returns any failures on ‘hash` if it were to be inserted.



22
23
24
25
26
27
28
# File 'lib/validate/kongo.rb', line 22

def validation_failures(hash)
  hash = hash.dup
  hash['_id'] = BSON::ObjectId.new unless hash.include?('_id')
  model = ::Kongo::Model.new(hash, coll)
  model.validates?
  model.failures
end