Module: ActsAsImportant::InstanceMethods

Defined in:
lib/acts_as_important/acts_as_important.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cached_importanceObject

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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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