Module: ActsAsImportant::InstanceMethods
- Defined in:
- lib/acts_as_important/acts_as_important.rb
Instance Attribute Summary collapse
-
#cached_importance ⇒ Object
Returns the value of attribute cached_importance.
Instance Method Summary collapse
- #acts_like_important? ⇒ Boolean
- #importance_indicator_for(user) ⇒ Object
- #importance_note_for(user) ⇒ Object
- #important_to!(user) ⇒ Object
- #important_to?(user) ⇒ Boolean
- #was_important_to?(user) ⇒ Boolean
Instance Attribute Details
#cached_importance ⇒ Object
Returns the value of attribute cached_importance.
44 45 46 |
# File 'lib/acts_as_important/acts_as_important.rb', line 44 def cached_importance @cached_importance end |
Instance Method Details
#acts_like_important? ⇒ Boolean
46 47 48 |
# File 'lib/acts_as_important/acts_as_important.rb', line 46 def acts_like_important? true end |
#importance_indicator_for(user) ⇒ Object
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/acts_as_important/acts_as_important.rb', line 68 def importance_indicator_for(user) case cached_importance when nil importance_indicators.loaded? ? importance_indicators.detect{|i| i.user_id == user.id} : importance_indicators.find_by_user_id(user.id) when false nil else cached_importance end end |
#importance_note_for(user) ⇒ Object
79 80 81 |
# File 'lib/acts_as_important/acts_as_important.rb', line 79 def importance_note_for(user) importance_indicator_for(user).try(:note) end |
#important_to!(user) ⇒ Object
50 51 52 53 54 |
# File 'lib/acts_as_important/acts_as_important.rb', line 50 def important_to!(user) importance_indicators.create(:user_id => user.id) unless important_to?(user) rescue ActiveRecord::RecordNotUnique # Database-level uniqueness constraint failed. return true end |
#important_to?(user) ⇒ Boolean
56 57 58 59 60 |
# File 'lib/acts_as_important/acts_as_important.rb', line 56 def important_to?(user) if indicator = importance_indicator_for(user) indicator.active? end end |
#was_important_to?(user) ⇒ Boolean
62 63 64 65 66 |
# File 'lib/acts_as_important/acts_as_important.rb', line 62 def was_important_to?(user) if indicator = importance_indicator_for(user) !indicator.active? end end |