Module: Mongoid::Toggleable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/mongoid/toggleable.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#toggle(toggleable_attribute) ⇒ Object
Public: Toggle the attribute specified.
-
#toggle!(toggleable_attribute) ⇒ Object
Public: Toggle the attribute specified and persist the change.
Instance Method Details
#toggle(toggleable_attribute) ⇒ Object
Public: Toggle the attribute specified
Returns the value the attribute was changed to. Does not persist the change.
46 47 48 |
# File 'lib/mongoid/toggleable.rb', line 46 def toggle(toggleable_attribute) send("#{toggleable_attribute}=", !send(toggleable_attribute)) end |
#toggle!(toggleable_attribute) ⇒ Object
Public: Toggle the attribute specified and persist the change
Returns the result of #save.
53 54 55 56 |
# File 'lib/mongoid/toggleable.rb', line 53 def toggle!(toggleable_attribute) toggle(toggleable_attribute) save end |