Module: Mongoid::Extensions::Object

Defined in:
build/mongoid-master/lib/mongoid/extensions/object.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#__evolve_object_id__Object Also known as: __mongoize_object_id__

Evolve a plain object into an object id.

Examples:

Evolve the object.

object.__evolve_object_id__

Returns:

Since:

  • 3.0.0



16
17
18
# File 'build/mongoid-master/lib/mongoid/extensions/object.rb', line 16

def __evolve_object_id__
  self
end

#__find_args__Object

Convert the object to args for a find query.

Examples:

Convert the object to args.

object.__find_args__

Returns:

Since:

  • 3.0.0



29
30
31
# File 'build/mongoid-master/lib/mongoid/extensions/object.rb', line 29

def __find_args__
  self
end

#__mongoize_time__Object

Deprecated.
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.

Mongoize a plain object into a time.

Examples:

Mongoize the object.

object.__mongoize_time__

Returns:

Since:

  • 3.0.0



47
48
49
# File 'build/mongoid-master/lib/mongoid/extensions/object.rb', line 47

def __mongoize_time__
  self
end

#__setter__String

Try to form a setter from this object.

Examples:

Try to form a setter.

object.__setter__

Returns:

  • (String)

    The object as a string plus =.

Since:

  • 3.1.0



59
60
61
# File 'build/mongoid-master/lib/mongoid/extensions/object.rb', line 59

def __setter__
  "#{self}="
end

#__sortable__Object

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

Examples:

Get the object as sort criteria.

object.__sortable__

Returns:

Since:

  • 3.0.0



71
72
73
# File 'build/mongoid-master/lib/mongoid/extensions/object.rb', line 71

def __sortable__
  self
end

#__to_inc__Object

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

Examples:

Convert the object.

1.__to_inc__

Returns:

Since:

  • 3.0.3



83
84
85
# File 'build/mongoid-master/lib/mongoid/extensions/object.rb', line 83

def __to_inc__
  self
end

#blank_criteria?false

Deprecated.

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.

Returns:

  • (false)

    Always false.

Since:

  • 3.1.0



99
100
101
# File 'build/mongoid-master/lib/mongoid/extensions/object.rb', line 99

def blank_criteria?
  false
end

#do_or_do_not(name, *args) ⇒ Object?

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

Examples:

Do or do not.

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

Parameters:

Returns:

  • (Object, nil)

    The result of the method call or nil if the method does not exist.

Since:

  • 2.0.0.rc.1



115
116
117
# File 'build/mongoid-master/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) ⇒ Object, false

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

Examples:

Get the value for an instance var.

document.ivar("person")

Parameters:

  • name (String)

    The name of the variable.

Returns:

  • (Object, false)

    The value or false.

Since:

  • 2.0.0.rc.1



129
130
131
132
133
134
135
136
# File 'build/mongoid-master/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

#mongoizeObject

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

Examples:

Mongoize the object.

object.mongoize

Returns:

Since:

  • 3.0.0



147
148
149
# File 'build/mongoid-master/lib/mongoid/extensions/object.rb', line 147

def mongoize
  self
end

#multi_arged?false

Is the object multi args.

Examples:

Is the object multi args?

object.multi_arged?

Returns:

  • (false)

    false.

Since:

  • 3.0.0



159
160
161
# File 'build/mongoid-master/lib/mongoid/extensions/object.rb', line 159

def multi_arged?
  false
end

#numeric?false

Is the object a number?

Examples:

Is the object a number?.

object.numeric?

Returns:

  • (false)

    Always false.

Since:

  • 3.0.0



171
172
173
# File 'build/mongoid-master/lib/mongoid/extensions/object.rb', line 171

def numeric?
  false
end

#remove_ivar(name) ⇒ true, false

Remove the instance variable for the provided name.

Examples:

Remove the instance variable

document.remove_ivar("person")

Parameters:

  • name (String)

    The name of the variable.

Returns:

  • (true, false)

    If the variable was defined.

Since:

  • 2.1.0



185
186
187
188
189
190
191
# File 'build/mongoid-master/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?false

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

Examples:

Is the object resizable?

object.resizable?

Returns:

  • (false)

    false.

Since:

  • 3.0.0



202
203
204
# File 'build/mongoid-master/lib/mongoid/extensions/object.rb', line 202

def resizable?
  false
end

#substitutableObject

Get the substitutable version of an object.

Examples:

Get the substitutable.

object.substitutable

Returns:

Since:

  • 2.0.0



214
215
216
# File 'build/mongoid-master/lib/mongoid/extensions/object.rb', line 214

def substitutable
  self
end

#you_must(name, *args) ⇒ Object?

You must unlearn what you have learned. – Yoda

Examples:

You must perform this execution.

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

Parameters:

Returns:

  • (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



230
231
232
# File 'build/mongoid-master/lib/mongoid/extensions/object.rb', line 230

def you_must(name, *args)
  frozen? ? nil : do_or_do_not(name, *args)
end