Module: Mongoid::Extensions::Object

Defined in:
lib/mongoid/extensions/object.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary (collapse)

Instance Method Details

- (Object) __evolve_object_id__ Also known as: __mongoize_object_id__

Evolve a plain object into an object id.

Examples:

Evolve the object.

object.__evolve_object_id__

Since:

  • 3.0.0



14
15
16
# File 'lib/mongoid/extensions/object.rb', line 14

def __evolve_object_id__
  self
end

- (Object) __find_args__

Convert the object to args for a find query.

Examples:

Convert the object to args.

object.__find_args__

Since:

  • 3.0.0



27
28
29
# File 'lib/mongoid/extensions/object.rb', line 27

def __find_args__
  self
end

- (Object) __mongoize_time__

Mongoize a plain object into a time.

Examples:

Mongoize the object.

object.__mongoize_time__

Since:

  • 3.0.0



39
40
41
# File 'lib/mongoid/extensions/object.rb', line 39

def __mongoize_time__
  self
end

- (String) __setter__

Try to form a setter from this object.

Examples:

Try to form a setter.

object.__setter__

Since:

  • 3.1.0



51
52
53
# File 'lib/mongoid/extensions/object.rb', line 51

def __setter__
  "#{self}="
end

- (Object) __sortable__

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

Examples:

Get the object as sort criteria.

object.__sortable__

Since:

  • 3.0.0



63
64
65
# File 'lib/mongoid/extensions/object.rb', line 63

def __sortable__
  self
end

- (Object) __to_inc__

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

Examples:

Convert the object.

1.__to_inc__

Since:

  • 3.0.3



75
76
77
# File 'lib/mongoid/extensions/object.rb', line 75

def __to_inc__
  self
end

- (true, false) blank_criteria?

Check if the object is part of a blank relation criteria.

Examples:

Is the object blank criteria?

"".blank_criteria?

Since:

  • 3.1.0



87
88
89
# File 'lib/mongoid/extensions/object.rb', line 87

def blank_criteria?
  false
end

- (Object?) do_or_do_not(name, *args)

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

Examples:

Do or do not.

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

Since:

  • 2.0.0.rc.1



103
104
105
# File 'lib/mongoid/extensions/object.rb', line 103

def do_or_do_not(name, *args)
  send(name, *args) if name && respond_to?(name)
end

- (Object, false) ivar(name)

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")

Since:

  • 2.0.0.rc.1



117
118
119
120
121
122
123
# File 'lib/mongoid/extensions/object.rb', line 117

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

- (Object) mongoize

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

Examples:

Mongoize the object.

object.mongoize

Since:

  • 3.0.0



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

def mongoize
  self
end

- (false) multi_arged?

Is the object multi args.

Examples:

Is the object multi args?

object.multi_arged?

Since:

  • 3.0.0



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

def multi_arged?
  false
end

- (false) numeric?

Is the object a number?

Examples:

Is the object a number?.

object.numeric?

Since:

  • 3.0.0



158
159
160
# File 'lib/mongoid/extensions/object.rb', line 158

def numeric?
  false
end

- (true, false) remove_ivar(name)

Remove the instance variable for the provided name.

Examples:

Remove the instance variable

document.remove_ivar("person")

Since:

  • 2.1.0



172
173
174
175
176
177
178
# File 'lib/mongoid/extensions/object.rb', line 172

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

- (false) resizable?

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

Examples:

Is the object resizable?

object.resizable?

Since:

  • 3.0.0



189
190
191
# File 'lib/mongoid/extensions/object.rb', line 189

def resizable?
  false
end

- (Object) substitutable

Get the substitutable version of an object.

Examples:

Get the substitutable.

object.substitutable

Since:

  • 2.0.0



201
202
203
# File 'lib/mongoid/extensions/object.rb', line 201

def substitutable
  self
end

- (Object?) you_must(name, *args)

You must unlearn what you have learned. – Yoda

Examples:

You must perform this execution.

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

Since:

  • 2.2.1



217
218
219
# File 'lib/mongoid/extensions/object.rb', line 217

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