Module: Mongoid::Extensions::Object::Checks

Included in:
Object
Defined in:
lib/mongoid/extensions/object/checks.rb

Overview

This module has object checks in it.

Instance Method Summary collapse

Instance Method Details

#_vacant?true, false

Since Active Support’s blank? check looks to see if the object responds to #empty? and will call it if it does, we need another way to check if the object is empty or nil in case the user has defined a field called “empty” on the document.

Examples:

Is the array vacant?

[].vacant?

Is the object vacant?

nil.vacant?

Returns:

  • (true, false)

    True if empty or nil, false if not.

Since:

  • 2.0.2



23
24
25
# File 'lib/mongoid/extensions/object/checks.rb', line 23

def _vacant?
  is_a?(::Array) || is_a?(::String) ? empty? : !self
end