Module: Mongoid::Extensions::Object
- Defined in:
- lib/mongoid/extensions/object.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#__evolve_object_id__ ⇒ Object
(also: #__mongoize_object_id__)
Evolve a plain object into an object id.
-
#__find_args__ ⇒ Object
Convert the object to args for a find query.
-
#__mongoize_time__ ⇒ Object
Mongoize a plain object into a time.
-
#__setter__ ⇒ String
Try to form a setter from this object.
-
#__sortable__ ⇒ Object
Get the value of the object as a mongo friendy sort value.
-
#__to_inc__ ⇒ Object
Conversion of an object to an $inc-able value.
-
#blank_criteria? ⇒ true, false
Check if the object is part of a blank relation criteria.
-
#do_or_do_not(name, *args) ⇒ Object?
Do or do not, there is no try.
-
#ivar(name) ⇒ Object?
Get the value for an instance variable or nil if it doesn’t exist.
-
#mongoize ⇒ Object
Turn the object from the ruby type we deal with to a Mongo friendly type.
-
#multi_arged? ⇒ false
Is the object multi args.
-
#numeric? ⇒ false
Is the object a number?.
-
#remove_ivar(name) ⇒ true, false
Remove the instance variable for the provided name.
-
#resizable? ⇒ false
Is the object’s size changable? Only returns true for arrays and hashes currently.
-
#substitutable ⇒ Object
Get the substitutable version of an object.
-
#you_must(name, *args) ⇒ Object?
You must unlearn what you have learned.
Instance Method Details
#__evolve_object_id__ ⇒ Object Also known as: __mongoize_object_id__
Evolve a plain object into an object id.
14 15 16 |
# File 'lib/mongoid/extensions/object.rb', line 14 def __evolve_object_id__ self end |
#__find_args__ ⇒ Object
Convert the object to args for a find query.
27 28 29 |
# File 'lib/mongoid/extensions/object.rb', line 27 def __find_args__ self end |
#__mongoize_time__ ⇒ Object
Mongoize a plain object into a time.
39 40 41 |
# File 'lib/mongoid/extensions/object.rb', line 39 def __mongoize_time__ self end |
#__setter__ ⇒ String
Try to form a setter from this object.
51 52 53 |
# File 'lib/mongoid/extensions/object.rb', line 51 def __setter__ "#{self}=" end |
#__sortable__ ⇒ Object
Get the value of the object as a mongo friendy sort value.
63 64 65 |
# File 'lib/mongoid/extensions/object.rb', line 63 def __sortable__ self end |
#__to_inc__ ⇒ Object
Conversion of an object to an $inc-able value.
75 76 77 |
# File 'lib/mongoid/extensions/object.rb', line 75 def __to_inc__ self end |
#blank_criteria? ⇒ true, false
Check if the object is part of a blank relation criteria.
87 88 89 |
# File 'lib/mongoid/extensions/object.rb', line 87 def blank_criteria? false end |
#do_or_do_not(name, *args) ⇒ Object?
Do or do not, there is no try. – Yoda.
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 |
#ivar(name) ⇒ Object?
Get the value for an instance variable or nil if it doesn’t exist.
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 |
#mongoize ⇒ Object
Turn the object from the ruby type we deal with to a Mongo friendly type.
134 135 136 |
# File 'lib/mongoid/extensions/object.rb', line 134 def mongoize self end |
#multi_arged? ⇒ false
Is the object multi args.
146 147 148 |
# File 'lib/mongoid/extensions/object.rb', line 146 def multi_arged? false end |
#numeric? ⇒ false
Is the object a number?
158 159 160 |
# File 'lib/mongoid/extensions/object.rb', line 158 def numeric? false end |
#remove_ivar(name) ⇒ true, false
Remove the instance variable for the provided name.
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 |
#resizable? ⇒ false
Is the object’s size changable? Only returns true for arrays and hashes currently.
189 190 191 |
# File 'lib/mongoid/extensions/object.rb', line 189 def resizable? false end |
#substitutable ⇒ Object
Get the substitutable version of an object.
201 202 203 |
# File 'lib/mongoid/extensions/object.rb', line 201 def substitutable self end |
#you_must(name, *args) ⇒ Object?
You must unlearn what you have learned. – Yoda
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 |