Module: Mongoid::Suicide::ClassMethods
- Defined in:
- lib/mongoid/suicide.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#remove_accessors(name, meth) ⇒ Object
Remove the field accessors.
-
#remove_dirty_change_accessor(meth) ⇒ Object
Removes the dirty change accessor.
-
#remove_dirty_change_check(meth) ⇒ Object
Removes the dirty change check.
-
#remove_dirty_change_flag(meth) ⇒ Object
Removes the dirty change flag.
-
#remove_dirty_default_change_check(meth) ⇒ Object
Removes the dirty default change check.
-
#remove_dirty_methods(meth) ⇒ Object
Removes the dirty change methods.
-
#remove_dirty_previous_value_accessor(meth) ⇒ Object
Removes the dirty change previous value accessor.
-
#remove_dirty_reset(meth) ⇒ Object
Removes the dirty change reset.
-
#remove_dirty_reset_to_default(meth) ⇒ Object
Removes the dirty change reset to default.
-
#remove_field(name) ⇒ Field
Removes the field from the Document.
-
#remove_field_check(meth) ⇒ Object
Remove the check method for the provided field.
-
#remove_field_getter(meth) ⇒ Object
Remove the getter method for the provided field.
-
#remove_field_getter_before_typecast(meth) ⇒ Object
Remove the getter_before_type_cast method for the provided field.
-
#remove_field_in_descendants(name) ⇒ Object
Removes the field from descendants.
-
#remove_field_setter(meth) ⇒ Object
Remove the setter method for the provided field.
-
#remove_translations_getter(meth) ⇒ Object
Remove the translation getter method for the provided field.
-
#remove_translations_setter(meth) ⇒ Object
Remove the translation setter method for the provided field.
-
#remove_validate_callbacks(a_name) ⇒ Object
Removes validate callbacks for the field.
-
#remove_validations_for(name) ⇒ Object
Removes validations for the field.
Instance Method Details
#remove_accessors(name, meth) ⇒ Object
Remove the field accessors.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/mongoid/suicide.rb', line 59 def remove_accessors(name, meth) field = fields[name] remove_field_getter(meth) remove_field_getter_before_typecast(meth) remove_field_setter(meth) remove_field_check(meth) return unless field.[:localize] remove_translations_getter(meth) remove_translations_setter(meth) localized_fields.delete(name) end |
#remove_dirty_change_accessor(meth) ⇒ Object
Removes the dirty change accessor.
218 219 220 221 222 |
# File 'lib/mongoid/suicide.rb', line 218 def remove_dirty_change_accessor(meth) generated_methods.module_eval do undef_method("#{meth}_change") if method_defined?("#{meth}_change") end end |
#remove_dirty_change_check(meth) ⇒ Object
Removes the dirty change check.
230 231 232 233 234 |
# File 'lib/mongoid/suicide.rb', line 230 def remove_dirty_change_check(meth) generated_methods.module_eval do undef_method("#{meth}_changed?") if method_defined?("#{meth}_changed?") end end |
#remove_dirty_change_flag(meth) ⇒ Object
Removes the dirty change flag.
242 243 244 245 246 |
# File 'lib/mongoid/suicide.rb', line 242 def remove_dirty_change_flag(meth) generated_methods.module_eval do undef_method("#{meth}_will_change!") if method_defined?("#{meth}_will_change!") end end |
#remove_dirty_default_change_check(meth) ⇒ Object
Removes the dirty default change check.
254 255 256 257 258 |
# File 'lib/mongoid/suicide.rb', line 254 def remove_dirty_default_change_check(meth) generated_methods.module_eval do undef_method("#{meth}_changed_from_default?") if method_defined?("#{meth}_changed_from_default?") end end |
#remove_dirty_methods(meth) ⇒ Object
Removes the dirty change methods.
88 89 90 91 92 93 94 95 96 |
# File 'lib/mongoid/suicide.rb', line 88 def remove_dirty_methods(meth) remove_dirty_change_accessor(meth) remove_dirty_change_check(meth) remove_dirty_change_flag(meth) remove_dirty_default_change_check(meth) remove_dirty_previous_value_accessor(meth) remove_dirty_reset(meth) remove_dirty_reset_to_default(meth) end |
#remove_dirty_previous_value_accessor(meth) ⇒ Object
Removes the dirty change previous value accessor.
266 267 268 269 270 |
# File 'lib/mongoid/suicide.rb', line 266 def remove_dirty_previous_value_accessor(meth) generated_methods.module_eval do undef_method("#{meth}_was") if method_defined?("#{meth}_was") end end |
#remove_dirty_reset(meth) ⇒ Object
Removes the dirty change reset.
278 279 280 281 282 |
# File 'lib/mongoid/suicide.rb', line 278 def remove_dirty_reset(meth) generated_methods.module_eval do undef_method("reset_#{meth}!") if method_defined?("reset_#{meth}!") end end |
#remove_dirty_reset_to_default(meth) ⇒ Object
Removes the dirty change reset to default.
290 291 292 293 294 |
# File 'lib/mongoid/suicide.rb', line 290 def remove_dirty_reset_to_default(meth) generated_methods.module_eval do undef_method("reset_#{meth}_to_default!") if method_defined?("reset_#{meth}_to_default!") end end |
#remove_field(name) ⇒ Field
Removes the field from the Document. A getter and setter will be removed.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/mongoid/suicide.rb', line 23 def remove_field(name) name = name.to_s return unless fields[name] aliased = fields[name].[:as] remove_accessors(name, name) remove_accessors(name, aliased) if aliased remove_dirty_methods(name) remove_dirty_methods(aliased) if aliased remove_defaults(name) remove_field_in_descendants(name) remove_validations_for(name) aliased_fields.delete(aliased.to_s) if aliased fields.delete(name) end |
#remove_field_check(meth) ⇒ Object
Remove the check method for the provided field.
180 181 182 183 184 |
# File 'lib/mongoid/suicide.rb', line 180 def remove_field_check(meth) generated_methods.module_eval do undef_method("#{meth}?") if method_defined?("#{meth}?") end end |
#remove_field_getter(meth) ⇒ Object
Remove the getter method for the provided field.
144 145 146 147 148 |
# File 'lib/mongoid/suicide.rb', line 144 def remove_field_getter(meth) generated_methods.module_eval do undef_method(meth) if method_defined?(meth) end end |
#remove_field_getter_before_typecast(meth) ⇒ Object
Remove the getter_before_type_cast method for the provided field.
156 157 158 159 160 |
# File 'lib/mongoid/suicide.rb', line 156 def remove_field_getter_before_typecast(meth) generated_methods.module_eval do undef_method("#{meth}_before_type_cast") if method_defined?("#{meth}_before_type_cast") end end |
#remove_field_in_descendants(name) ⇒ Object
Removes the field from descendants.
101 102 103 |
# File 'lib/mongoid/suicide.rb', line 101 def remove_field_in_descendants(name) descendants.each { |descendant| descendant.remove_field(name) } end |
#remove_field_setter(meth) ⇒ Object
Remove the setter method for the provided field.
168 169 170 171 172 |
# File 'lib/mongoid/suicide.rb', line 168 def remove_field_setter(meth) generated_methods.module_eval do undef_method("#{meth}=") if method_defined?("#{meth}=") end end |
#remove_translations_getter(meth) ⇒ Object
Remove the translation getter method for the provided field.
192 193 194 195 196 197 |
# File 'lib/mongoid/suicide.rb', line 192 def remove_translations_getter(meth) generated_methods.module_eval do undef_method("#{meth}_translations") if method_defined?("#{meth}_translations") undef_method("#{meth}_t") if method_defined?("#{meth}_t") end end |
#remove_translations_setter(meth) ⇒ Object
Remove the translation setter method for the provided field.
205 206 207 208 209 210 |
# File 'lib/mongoid/suicide.rb', line 205 def remove_translations_setter(meth) generated_methods.module_eval do undef_method("#{meth}_translations=") if method_defined?("#{meth}_translations=") undef_method("#{meth}_t=") if method_defined?("#{meth}_t=") end end |
#remove_validate_callbacks(a_name) ⇒ Object
Removes validate callbacks for the field.
125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/mongoid/suicide.rb', line 125 def remove_validate_callbacks(a_name) chain = _validate_callbacks.dup.reject do |callback| f = callback.filter f.respond_to?(:attributes) && f.attributes == a_name end reset_callbacks(:validate) chain.each do |callback| set_callback 'validate', callback.filter end end |
#remove_validations_for(name) ⇒ Object
Removes validations for the field.
111 112 113 114 115 116 117 |
# File 'lib/mongoid/suicide.rb', line 111 def remove_validations_for(name) name = name.to_sym a_name = [name] _validators.reject! { |key, _| key == name } remove_validate_callbacks a_name end |