Module: Mongoid::Validatable::Queryable

Included in:
UniquenessValidator
Defined in:
build/mongoid-8.1/lib/mongoid/validatable/queryable.rb

Instance Method Summary collapse

Instance Method Details

#with_query(document) ⇒ Object

Wrap the validation inside the an execution block that alert’s the client not to clear its persistence options.

Examples:

Execute the validation with a query.

with_query(document) do
  #...
end

Parameters:

  • document (Document)

    The document being validated.

Returns:

  • (Object)

    The result of the yield.



18
19
20
21
22
23
24
25
26
# File 'build/mongoid-8.1/lib/mongoid/validatable/queryable.rb', line 18

def with_query(document)
  klass = document.class
  begin
    Threaded.begin_execution("#{klass.name}-validate-with-query")
    yield
  ensure
    Threaded.exit_execution("#{klass.name}-validate-with-query")
  end
end