Module: FlagThis::Flag::ClassMethods
- Defined in:
- lib/flag_methods.rb
Instance Method Summary collapse
-
#find_flaggable(flaggable_str, flaggable_id) ⇒ Object
Helper class method to look up a flaggable object given the flaggable class name and id.
-
#find_flags_by_user(user, role = "abuse") ⇒ Object
Helper class method to lookup all flags assigned to all flaggable types for a given user.
-
#find_flags_for_flaggable(flaggable_str, flaggable_id, role = "abuse") ⇒ Object
Helper class method to look up all flags for flaggable class name and flaggable id.
- #this_is_a_flag ⇒ Object
Instance Method Details
#find_flaggable(flaggable_str, flaggable_id) ⇒ Object
Helper class method to look up a flaggable object given the flaggable class name and id
35 36 37 38 |
# File 'lib/flag_methods.rb', line 35 def find_flaggable(flaggable_str, flaggable_id) model = flaggable_str.constantize model.respond_to?(:find_flags_for) ? model.find(flaggable_id) : nil end |
#find_flags_by_user(user, role = "abuse") ⇒ Object
Helper class method to lookup all flags assigned to all flaggable types for a given user.
23 24 25 |
# File 'lib/flag_methods.rb', line 23 def find_flags_by_user(user, role = "abuse") where(["user_id = ? and role = ?", user.id, role]).order("created_at DESC") end |
#find_flags_for_flaggable(flaggable_str, flaggable_id, role = "abuse") ⇒ Object
Helper class method to look up all flags for flaggable class name and flaggable id.
29 30 31 |
# File 'lib/flag_methods.rb', line 29 def find_flags_for_flaggable(flaggable_str, flaggable_id, role = "abuse") where(["flaggable_type = ? and flaggable_id = ? and role = ?", flaggable_str, flaggable_id, role]).order("created_at DESC") end |
#this_is_a_flag ⇒ Object
17 18 19 20 |
# File 'lib/flag_methods.rb', line 17 def this_is_a_flag #after_create :callback_flaggable end |