Module: Flagable::FlagableInstanceMethods
- Defined in:
- app/models/flagable.rb
Instance Method Summary collapse
- #add_flag(new_flag) ⇒ Object
- #add_flags(*new_flags) ⇒ Object
- #flags_to_syms ⇒ Object
- #has_flag?(flag) ⇒ Boolean
- #remove_flag(flag_to_remove) ⇒ Object
- #remove_flags(*flags_to_remove) ⇒ Object
Instance Method Details
#add_flag(new_flag) ⇒ Object
32 33 34 |
# File 'app/models/flagable.rb', line 32 def add_flag( new_flag ) self.add_flags new_flag end |
#add_flags(*new_flags) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/models/flagable.rb', line 20 def add_flags( *new_flags ) if new_flags.kind_of? Array for new_flag in new_flags if new_flag.kind_of? String or new_flag.kind_of? Symbol if not self.has_flag? new_flag self.flags.create( key: new_flag.to_sym ) end end end end end |
#flags_to_syms ⇒ Object
44 45 46 |
# File 'app/models/flagable.rb', line 44 def flags_to_syms self.flags.pluck(:key).map(&:to_sym) end |
#has_flag?(flag) ⇒ Boolean
48 49 50 |
# File 'app/models/flagable.rb', line 48 def has_flag?( flag ) self.flags_to_syms.include? flag end |
#remove_flag(flag_to_remove) ⇒ Object
40 41 42 |
# File 'app/models/flagable.rb', line 40 def remove_flag( flag_to_remove ) self.remove_flags flag_to_remove end |
#remove_flags(*flags_to_remove) ⇒ Object
36 37 38 |
# File 'app/models/flagable.rb', line 36 def remove_flags(*flags_to_remove) self.flags.where(key: flags_to_remove).destroy_all end |