module Mongoid::Extensions::Object

Public Instance Methods

__evolve_object_id__() click to toggle source

Evolve a plain object into an object id.

@example Evolve the object.

object.__evolve_object_id__

@return [ Object ] self.

@since 3.0.0

# File lib/mongoid/extensions/object.rb, line 16
def __evolve_object_id__
  self
end
Also aliased as: __mongoize_object_id__
__find_args__() click to toggle source

Convert the object to args for a find query.

@example Convert the object to args.

object.__find_args__

@return [ Object ] self.

@since 3.0.0

# File lib/mongoid/extensions/object.rb, line 29
def __find_args__
  self
end
__mongoize_object_id__()
__mongoize_time__() click to toggle source

Mongoize a plain object into a time.

@note This method should not be used, because it does not

return correct results for non-Time objects. Override
__mongoize_time__ in classes that are time-like to return an
instance of Time or ActiveSupport::TimeWithZone.

@example Mongoize the object.

object.__mongoize_time__

@return [ Object ] self.

@since 3.0.0 @deprecated

# File lib/mongoid/extensions/object.rb, line 47
def __mongoize_time__
  self
end
__setter__() click to toggle source

Try to form a setter from this object.

@example Try to form a setter.

object.__setter__

@return [ String ] The object as a string plus =.

@since 3.1.0

# File lib/mongoid/extensions/object.rb, line 59
def __setter__
  "#{self}="
end
__sortable__() click to toggle source

Get the value of the object as a mongo friendy sort value.

@example Get the object as sort criteria.

object.__sortable__

@return [ Object ] self.

@since 3.0.0

# File lib/mongoid/extensions/object.rb, line 71
def __sortable__
  self
end
__to_inc__() click to toggle source

Conversion of an object to an $inc-able value.

@example Convert the object.

1.__to_inc__

@return [ Object ] The object.

@since 3.0.3

# File lib/mongoid/extensions/object.rb, line 83
def __to_inc__
  self
end
blank_criteria?() click to toggle source

Checks whether conditions given in this object are known to be unsatisfiable, i.e., querying with this object will always return no documents.

This method is deprecated. Mongoid now uses _mongoid_unsatisfiable_criteria? internally; this method is retained for backwards compatibility only. It always returns false.

@return [ false ] Always false.

@since 3.1.0 @deprecated

# File lib/mongoid/extensions/object.rb, line 99
def blank_criteria?
  false
end
do_or_do_not(name, *args) click to toggle source

Do or do not, there is no try. – Yoda.

@example Do or do not.

object.do_or_do_not(:use, "The Force")

@param [ String, Symbol ] name The method name. @param [ Array ] args The arguments.

@return [ Object, nil ] The result of the method call or nil if the

method does not exist.

@since 2.0.0.rc.1

# File lib/mongoid/extensions/object.rb, line 115
def do_or_do_not(name, *args)
  send(name, *args) if name && respond_to?(name)
end
ivar(name) click to toggle source

Get the value for an instance variable or false if it doesn’t exist.

@example Get the value for an instance var.

document.ivar("person")

@param [ String ] name The name of the variable.

@return [ Object, false ] The value or false.

@since 2.0.0.rc.1

# File lib/mongoid/extensions/object.rb, line 129
def ivar(name)
  var_name = "@_#{name}"
  if instance_variable_defined?(var_name)
    return instance_variable_get(var_name)
  else
    false
  end
end
mongoize() click to toggle source

Turn the object from the ruby type we deal with to a Mongo friendly type.

@example Mongoize the object.

object.mongoize

@return [ Object ] The object.

@since 3.0.0

# File lib/mongoid/extensions/object.rb, line 147
def mongoize
  self
end
multi_arged?() click to toggle source

Is the object multi args.

@example Is the object multi args?

object.multi_arged?

@return [ false ] false.

@since 3.0.0

# File lib/mongoid/extensions/object.rb, line 159
def multi_arged?
  false
end
numeric?() click to toggle source

Is the object a number?

@example Is the object a number?.

object.numeric?

@return [ false ] Always false.

@since 3.0.0

# File lib/mongoid/extensions/object.rb, line 171
def numeric?
  false
end
remove_ivar(name) click to toggle source

Remove the instance variable for the provided name.

@example Remove the instance variable

document.remove_ivar("person")

@param [ String ] name The name of the variable.

@return [ true, false ] If the variable was defined.

@since 2.1.0

# File lib/mongoid/extensions/object.rb, line 185
def remove_ivar(name)
  if instance_variable_defined?("@_#{name}")
    return remove_instance_variable("@_#{name}")
  else
    false
  end
end
resizable?() click to toggle source

Is the object’s size changable? Only returns true for arrays and hashes currently.

@example Is the object resizable?

object.resizable?

@return [ false ] false.

@since 3.0.0

# File lib/mongoid/extensions/object.rb, line 202
def resizable?
  false
end
substitutable() click to toggle source

Get the substitutable version of an object.

@example Get the substitutable.

object.substitutable

@return [ Object ] self.

@since 2.0.0

# File lib/mongoid/extensions/object.rb, line 214
def substitutable
  self
end
you_must(name, *args) click to toggle source

You must unlearn what you have learned. – Yoda

@example You must perform this execution.

object.you_must(:use, "The Force")

@param [ String, Symbol ] name The method name. @param [ Array ] args The arguments.

@return [ Object, nil ] The result of the method call or nil if the

method does not exist. Nil if the object is frozen.

@since 2.2.1

# File lib/mongoid/extensions/object.rb, line 230
def you_must(name, *args)
  frozen? ? nil : do_or_do_not(name, *args)
end