Module: Mentionable
- Defined in:
- lib/mentionable.rb,
lib/mentionable/version.rb
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- REGEXP =
/@[\w-]+/.freeze
- VERSION =
'0.3.0'
Class Method Summary collapse
Instance Method Summary collapse
- #extract_mentions(text) ⇒ Object
- #mentionable ⇒ Object
- #mentionable_before_last_save ⇒ Object
- #mentions ⇒ Object
- #mentions? ⇒ Boolean
- #mentions_were ⇒ Object
- #new_mentions ⇒ Object
- #new_mentions? ⇒ Boolean
Class Method Details
.included(base) ⇒ Object
8 9 10 |
# File 'lib/mentionable.rb', line 8 def self.included(base) base.extend ClassMethods end |
Instance Method Details
#extract_mentions(text) ⇒ Object
37 38 39 |
# File 'lib/mentionable.rb', line 37 def extract_mentions(text) text.scan(self.class.regexp).uniq end |
#mentionable ⇒ Object
41 42 43 |
# File 'lib/mentionable.rb', line 41 def mentionable send self.class.mentionable_name end |
#mentionable_before_last_save ⇒ Object
45 46 47 |
# File 'lib/mentionable.rb', line 45 def mentionable_before_last_save send "#{self.class.mentionable_name}_before_last_save" end |
#mentions ⇒ Object
49 50 51 |
# File 'lib/mentionable.rb', line 49 def mentions extract_mentions(mentionable) end |
#mentions? ⇒ Boolean
53 54 55 |
# File 'lib/mentionable.rb', line 53 def mentions? mentions.present? end |
#mentions_were ⇒ Object
57 58 59 |
# File 'lib/mentionable.rb', line 57 def mentions_were extract_mentions(mentionable_before_last_save || '') end |
#new_mentions ⇒ Object
61 62 63 |
# File 'lib/mentionable.rb', line 61 def new_mentions mentions - mentions_were end |
#new_mentions? ⇒ Boolean
65 66 67 |
# File 'lib/mentionable.rb', line 65 def new_mentions? new_mentions.present? end |