Module: Mongoid::Document::Flagable::InstanceMethods
- Defined in:
- lib/mongoid-flags.rb
Instance Method Summary collapse
-
#add_flag(flag) ⇒ Object
Adds a flag, and you need to explicitly save the object.
-
#add_flag!(flag) ⇒ Object
Adds a flag, and saves the object.
-
#has_flag?(flag) ⇒ Boolean
Checks if a flag exists.
-
#remove_flag(flag) ⇒ Object
Removes a flag, and you need to explicitly save the object.
-
#remove_flag!(flag) ⇒ Object
Removes a flag, and saves the object.
Instance Method Details
#add_flag(flag) ⇒ Object
Adds a flag, and you need to explicitly save the object
18 19 20 21 22 |
# File 'lib/mongoid-flags.rb', line 18 def add_flag(flag) (self.flags ||= []) << flag self.flags.uniq! self.flags end |
#add_flag!(flag) ⇒ Object
Adds a flag, and saves the object
25 26 27 28 29 |
# File 'lib/mongoid-flags.rb', line 25 def add_flag!(flag) add_flag(flag) save! self.flags end |
#has_flag?(flag) ⇒ Boolean
Checks if a flag exists
32 33 34 |
# File 'lib/mongoid-flags.rb', line 32 def has_flag?(flag) (self.flags || []).include?(flag) end |
#remove_flag(flag) ⇒ Object
Removes a flag, and you need to explicitly save the object
38 39 40 |
# File 'lib/mongoid-flags.rb', line 38 def remove_flag(flag) (self.flags || []).delete_if { |n| n.casecmp(flag) == 0 } end |
#remove_flag!(flag) ⇒ Object
Removes a flag, and saves the object
43 44 45 46 47 |
# File 'lib/mongoid-flags.rb', line 43 def remove_flag!(flag) remove_flag(flag) save! self.flags end |