Sha256: f12ce14af7e39b5f60d760366a1ab85917c7442a24a3424d37eeb88cb7617307

Contents?: true

Size: 914 Bytes

Versions: 19

Compression:

Stored size: 914 Bytes

Contents

# encoding: utf-8
module Mongoid #:nodoc:
  module Extensions #:nodoc:
    module Object #:nodoc:

      # This module has object checks in it.
      module Checks #:nodoc:

        # 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.
        #
        # @example Is the array vacant?
        #   [].vacant?
        #
        # @example Is the hash vacant?
        #   {}.vacant?
        #
        # @example Is the object vacant?
        #   nil.vacant?
        #
        # @return [ true, false ] True if empty or nil, false if not.
        #
        # @since 2.0.2
        def _vacant?
          is_a?(::Enumerable) || is_a?(::String) ? empty? : !self
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 2 rubygems

Version Path
mongoid-2.3.2 lib/mongoid/extensions/object/checks.rb
mongoid-2.2.3 lib/mongoid/extensions/object/checks.rb
mongoid-2.3.1 lib/mongoid/extensions/object/checks.rb
mongoid-2.3.0 lib/mongoid/extensions/object/checks.rb
mongoid-2.2.2 lib/mongoid/extensions/object/checks.rb
mongoid-2.2.1 lib/mongoid/extensions/object/checks.rb
mongoid-2.2.0 lib/mongoid/extensions/object/checks.rb
mongoid-2.1.9 lib/mongoid/extensions/object/checks.rb
mongoid-2.1.8 lib/mongoid/extensions/object/checks.rb
mongoid-2.1.7 lib/mongoid/extensions/object/checks.rb
mongoid-2.1.6 lib/mongoid/extensions/object/checks.rb
mongoid-2.1.5 lib/mongoid/extensions/object/checks.rb
mongoid-2.1.4 lib/mongoid/extensions/object/checks.rb
mongoid-2.1.3 lib/mongoid/extensions/object/checks.rb
mongoid-2.1.2 lib/mongoid/extensions/object/checks.rb
mongoid-2.1.1 lib/mongoid/extensions/object/checks.rb
mongoid-2.1.0 lib/mongoid/extensions/object/checks.rb
mongoid-braxton-2.0.2 lib/mongoid/extensions/object/checks.rb
mongoid-2.0.2 lib/mongoid/extensions/object/checks.rb