123456789_123456789_123456789_123456789_123456789_

Module: Mongoid::Extensions::Object

Relationships & Source Files
Namespace Children
Modules:
Defined in: lib/mongoid/extensions/object.rb

Overview

Adds type-casting behavior to Object class.

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Class Method Details

.included(base)

[ GitHub ]

  
# File 'lib/mongoid/extensions/object.rb', line 8

def self.included(base)
  base.extend(ClassMethods)
end

Instance Attribute Details

#multi_arged?false (readonly)

Deprecated.

Is the object multi args.

Examples:

Is the object multi args?

object.multi_arged?

Returns:

  • (false)

    false.

[ GitHub ]

  
# File 'lib/mongoid/extensions/object.rb', line 123

def multi_arged?
  false
end

#numeric?false (readonly)

Is the object a number?

Examples:

Is the object a number?.

object.numeric?

Returns:

  • (false)

    Always false.

[ GitHub ]

  
# File 'lib/mongoid/extensions/object.rb', line 134

def numeric?
  false
end

#resizable?false (readonly)

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

Examples:

Is the object resizable?

object.resizable?

Returns:

  • (false)

    false.

[ GitHub ]

  
# File 'lib/mongoid/extensions/object.rb', line 161

def resizable?
  false
end

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:

  • (Object)

    self.

[ GitHub ]

  
# File 'lib/mongoid/extensions/object.rb', line 18

def __evolve_object_id__
  self
end

#__find_args__Object

Deprecated.

Convert the object to args for a find query.

Examples:

Convert the object to args.

object.__find_args__

Returns:

  • (Object)

    self.

[ GitHub ]

  
# File 'lib/mongoid/extensions/object.rb', line 30

def __find_args__
  self
end

#__mongoize_object_id__

Alias for Mongoid::Extensions::Object#evolve_object_id.

[ GitHub ]

  
# File 'lib/mongoid/extensions/object.rb', line 21

alias :__mongoize_object_id__ :__evolve_object_id__

#__setter__String

Deprecated.

Try to form a setter from this object.

Examples:

Try to form a setter.

object.__setter__

Returns:

  • (String)

    The object as a string plus =.

[ GitHub ]

  
# File 'lib/mongoid/extensions/object.rb', line 42

def __setter__
  "#{self}="
end

#__sortable__Object

Deprecated.

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

Examples:

Get the object as sort criteria.

object.__sortable__

Returns:

  • (Object)

    self.

[ GitHub ]

  
# File 'lib/mongoid/extensions/object.rb', line 54

def __sortable__
  self
end

#__to_inc__Object

Deprecated.

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

Examples:

Convert the object.

1.__to_inc__

Returns:

  • (Object)

    The object.

[ GitHub ]

  
# File 'lib/mongoid/extensions/object.rb', line 66

def __to_inc__
  self
end

#do_or_do_not(name, *args) ⇒ Object | nil

Deprecated.

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

Examples:

Do or do not.

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

Parameters:

  • name (String | Symbol)

    The method name.

  • *args (Object...)

    The arguments.

Returns:

  • (Object | nil)

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

[ GitHub ]

  
# File 'lib/mongoid/extensions/object.rb', line 83

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.

[ GitHub ]

  
# File 'lib/mongoid/extensions/object.rb', line 96

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:

  • (Object)

    The object.

[ GitHub ]

  
# File 'lib/mongoid/extensions/object.rb', line 112

def mongoize
  self
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.

[ GitHub ]

  
# File 'lib/mongoid/extensions/object.rb', line 146

def remove_ivar(name)
  if instance_variable_defined?("@_#{name}")
    return remove_instance_variable("@_#{name}")
  else
    false
  end
end

#substitutableObject

Get the substitutable version of an object.

Examples:

Get the substitutable.

object.substitutable

Returns:

  • (Object)

    self.

[ GitHub ]

  
# File 'lib/mongoid/extensions/object.rb', line 171

def substitutable
  self
end

#you_must(name, *args) ⇒ Object | nil

Deprecated.

You must unlearn what you have learned. – Yoda

Examples:

You must perform this execution.

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

Parameters:

  • name (String | Symbol)

    The method name.

  • *args (Object...)

    The arguments.

Returns:

  • (Object | nil)

    The result of the method call or nil if the method does not exist. Nil if the object is frozen.

[ GitHub ]

  
# File 'lib/mongoid/extensions/object.rb', line 186

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