Sha256: e599045ea8c5b0865f3b91d3815474e890b90cbf4cbf18fd78d0d5a149dc5375

Contents?: true

Size: 807 Bytes

Versions: 11

Compression:

Stored size: 807 Bytes

Contents

# encoding: utf-8
module Mongoid
  module Validations
    module Queryable

      # Wrap the validation inside the an execution block that alert's the
      # session not to clear its persistence options.
      #
      # @example Execute the validation with a query.
      #   with_query(document) do
      #     #...
      #   end
      #
      # @param [ Document ] document The document being validated.
      #
      # @return [ Object ] The result of the yield.
      #
      # @since 3.0.2
      def with_query(document)
        begin
          Threaded.begin("#{klass.name}-validate-with-query")
          yield
        ensure
          klass.clear_persistence_options unless document.errors.empty?
          Threaded.exit("#{klass.name}-validate-with-query")
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
mongoid-3.0.19 lib/mongoid/validations/queryable.rb
mongoid-3.0.18 lib/mongoid/validations/queryable.rb
mongoid-3.0.17 lib/mongoid/validations/queryable.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.16/lib/mongoid/validations/queryable.rb
mongoid-3.0.16 lib/mongoid/validations/queryable.rb
mongoid-3.0.15 lib/mongoid/validations/queryable.rb
mongoid-3.0.14 lib/mongoid/validations/queryable.rb
mongoid-3.0.13 lib/mongoid/validations/queryable.rb
mongoid-3.0.12 lib/mongoid/validations/queryable.rb
mongoid-3.0.11 lib/mongoid/validations/queryable.rb
mongoid-3.0.10 lib/mongoid/validations/queryable.rb