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.
- #__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
7 8 9 |
# File 'lib/mongoid/extensions/object.rb', line 7 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.
17 18 19 |
# File 'lib/mongoid/extensions/object.rb', line 17 def __evolve_object_id__ self end |
#__find_args__ ⇒ Object
Convert the object to args for a find query.
29 30 31 |
# File 'lib/mongoid/extensions/object.rb', line 29 def __find_args__ self end |
#__setter__ ⇒ String
Try to form a setter from this object.
41 42 43 |
# File 'lib/mongoid/extensions/object.rb', line 41 def __setter__ "#{self}=" end |
#__sortable__ ⇒ Object
Get the value of the object as a mongo friendly sort value.
53 54 55 |
# File 'lib/mongoid/extensions/object.rb', line 53 def __sortable__ self end |
#__to_inc__ ⇒ Object
Conversion of an object to an $inc-able value.
65 66 67 |
# File 'lib/mongoid/extensions/object.rb', line 65 def __to_inc__ self end |
#do_or_do_not(name, *args) ⇒ Object | nil
Do or do not, there is no try. -- Yoda.
81 82 83 |
# File 'lib/mongoid/extensions/object.rb', line 81 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.
94 95 96 97 98 99 |
# File 'lib/mongoid/extensions/object.rb', line 94 def ivar(name) var_name = "@_#{name}" return instance_variable_get(var_name) if instance_variable_defined?(var_name) false end |
#mongoize ⇒ Object
Turn the object from the ruby type we deal with to a Mongo friendly type.
108 109 110 |
# File 'lib/mongoid/extensions/object.rb', line 108 def mongoize self end |
#multi_arged? ⇒ false
Is the object multi args.
119 120 121 |
# File 'lib/mongoid/extensions/object.rb', line 119 def multi_arged? false end |
#numeric? ⇒ false
Is the object a number?
130 131 132 |
# File 'lib/mongoid/extensions/object.rb', line 130 def numeric? false end |
#remove_ivar(name) ⇒ true | false
Remove the instance variable for the provided name.
142 143 144 145 146 |
# File 'lib/mongoid/extensions/object.rb', line 142 def remove_ivar(name) return remove_instance_variable("@_#{name}") if instance_variable_defined?("@_#{name}") false end |
#resizable? ⇒ false
Is the object's size changable? Only returns true for arrays and hashes currently.
155 156 157 |
# File 'lib/mongoid/extensions/object.rb', line 155 def resizable? false end |
#substitutable ⇒ Object
Get the substitutable version of an object.
165 166 167 |
# File 'lib/mongoid/extensions/object.rb', line 165 def substitutable self end |
#you_must(name, *args) ⇒ Object | nil
You must unlearn what you have learned. -- Yoda
180 181 182 |
# File 'lib/mongoid/extensions/object.rb', line 180 def you_must(name, *args) frozen? ? nil : do_or_do_not(name, *args) end |