Module: Mongoid::Extensions::Object
- Defined in:
- lib/mongoid/extensions/object.rb
Overview
Adds type-casting behavior to Object class.
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#__evolve_object_id__ ⇒ Object
(also: #__mongoize_object_id__)
Evolve a plain object into an object id.
- #__find_args__ ⇒ Object deprecated Deprecated.
- #__mongoize_time__ ⇒ Object deprecated Deprecated.
- #__setter__ ⇒ String deprecated Deprecated.
- #__sortable__ ⇒ Object deprecated Deprecated.
- #__to_inc__ ⇒ Object deprecated Deprecated.
- #do_or_do_not(name, *args) ⇒ Object | nil deprecated Deprecated.
-
#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 deprecated Deprecated.
-
#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 | nil deprecated Deprecated.
Class Method Details
.included(base) ⇒ Object
8 9 10 |
# File 'lib/mongoid/extensions/object.rb', line 8 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#__evolve_object_id__ ⇒ Object Also known as: __mongoize_object_id__
Evolve a plain object into an object id.
18 19 20 |
# File 'lib/mongoid/extensions/object.rb', line 18 def __evolve_object_id__ self end |
#__find_args__ ⇒ Object
Convert the object to args for a find query.
30 31 32 |
# File 'lib/mongoid/extensions/object.rb', line 30 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.
47 48 49 |
# File 'lib/mongoid/extensions/object.rb', line 47 def __mongoize_time__ self end |
#__setter__ ⇒ String
Try to form a setter from this object.
58 59 60 |
# File 'lib/mongoid/extensions/object.rb', line 58 def __setter__ "#{self}=" end |
#__sortable__ ⇒ Object
Get the value of the object as a mongo friendly sort value.
70 71 72 |
# File 'lib/mongoid/extensions/object.rb', line 70 def __sortable__ self end |
#__to_inc__ ⇒ Object
Conversion of an object to an $inc-able value.
82 83 84 |
# File 'lib/mongoid/extensions/object.rb', line 82 def __to_inc__ self end |
#do_or_do_not(name, *args) ⇒ Object | nil
Do or do not, there is no try. – Yoda.
99 100 101 |
# File 'lib/mongoid/extensions/object.rb', line 99 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.
112 113 114 115 116 117 118 119 |
# File 'lib/mongoid/extensions/object.rb', line 112 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.
128 129 130 |
# File 'lib/mongoid/extensions/object.rb', line 128 def mongoize self end |
#multi_arged? ⇒ false
Is the object multi args.
139 140 141 |
# File 'lib/mongoid/extensions/object.rb', line 139 def multi_arged? false end |
#numeric? ⇒ false
Is the object a number?
150 151 152 |
# File 'lib/mongoid/extensions/object.rb', line 150 def numeric? false end |
#remove_ivar(name) ⇒ true | false
Remove the instance variable for the provided name.
162 163 164 165 166 167 168 |
# File 'lib/mongoid/extensions/object.rb', line 162 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.
177 178 179 |
# File 'lib/mongoid/extensions/object.rb', line 177 def resizable? false end |
#substitutable ⇒ Object
Get the substitutable version of an object.
187 188 189 |
# File 'lib/mongoid/extensions/object.rb', line 187 def substitutable self end |
#you_must(name, *args) ⇒ Object | nil
You must unlearn what you have learned. – Yoda
202 203 204 |
# File 'lib/mongoid/extensions/object.rb', line 202 def you_must(name, *args) frozen? ? nil : do_or_do_not(name, *args) end |