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 deprecated Deprecated.
-
#__setter__ ⇒ String
Try to form a setter from this object.
-
#__sortable__ ⇒ Object
Get the value of the object as a mongo friendly sort value.
-
#__to_inc__ ⇒ Object
Conversion of an object to an $inc-able value.
- #blank_criteria? ⇒ false deprecated Deprecated.
-
#do_or_do_not(name, *args) ⇒ Object?
Do or do not, there is no try.
-
#ivar(name) ⇒ Object, false
Get the value for an instance variable or false 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.
13 14 15 |
# File 'lib/mongoid/extensions/object.rb', line 13 def __evolve_object_id__ self end |
#__find_args__ ⇒ Object
Convert the object to args for a find query.
24 25 26 |
# File 'lib/mongoid/extensions/object.rb', line 24 def __find_args__ self end |
#__mongoize_time__ ⇒ Object
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.
40 41 42 |
# File 'lib/mongoid/extensions/object.rb', line 40 def __mongoize_time__ self end |
#__setter__ ⇒ String
Try to form a setter from this object.
50 51 52 |
# File 'lib/mongoid/extensions/object.rb', line 50 def __setter__ "#{self}=" end |
#__sortable__ ⇒ Object
Get the value of the object as a mongo friendly sort value.
60 61 62 |
# File 'lib/mongoid/extensions/object.rb', line 60 def __sortable__ self end |
#__to_inc__ ⇒ Object
Conversion of an object to an $inc-able value.
70 71 72 |
# File 'lib/mongoid/extensions/object.rb', line 70 def __to_inc__ self end |
#blank_criteria? ⇒ false
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.
84 85 86 |
# File 'lib/mongoid/extensions/object.rb', line 84 def blank_criteria? false end |
#do_or_do_not(name, *args) ⇒ Object?
Do or do not, there is no try. – Yoda.
98 99 100 |
# File 'lib/mongoid/extensions/object.rb', line 98 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.
110 111 112 113 114 115 116 117 |
# File 'lib/mongoid/extensions/object.rb', line 110 def ivar(name) var_name = "@_#{name}" if instance_variable_defined?(var_name) return instance_variable_get(var_name) else false end end |
#mongoize ⇒ Object
Turn the object from the ruby type we deal with to a Mongo friendly type.
126 127 128 |
# File 'lib/mongoid/extensions/object.rb', line 126 def mongoize self end |
#multi_arged? ⇒ false
Is the object multi args.
136 137 138 |
# File 'lib/mongoid/extensions/object.rb', line 136 def multi_arged? false end |
#numeric? ⇒ false
Is the object a number?
146 147 148 |
# File 'lib/mongoid/extensions/object.rb', line 146 def numeric? false end |
#remove_ivar(name) ⇒ true, false
Remove the instance variable for the provided name.
158 159 160 161 162 163 164 |
# File 'lib/mongoid/extensions/object.rb', line 158 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.
173 174 175 |
# File 'lib/mongoid/extensions/object.rb', line 173 def resizable? false end |
#substitutable ⇒ Object
Get the substitutable version of an object.
183 184 185 |
# File 'lib/mongoid/extensions/object.rb', line 183 def substitutable self end |
#you_must(name, *args) ⇒ Object?
You must unlearn what you have learned. – Yoda
197 198 199 |
# File 'lib/mongoid/extensions/object.rb', line 197 def you_must(name, *args) frozen? ? nil : do_or_do_not(name, *args) end |