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

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

#mentionableObject



41
42
43
# File 'lib/mentionable.rb', line 41

def mentionable
  send self.class.mentionable_name
end

#mentionable_before_last_saveObject



45
46
47
# File 'lib/mentionable.rb', line 45

def mentionable_before_last_save
  send "#{self.class.mentionable_name}_before_last_save"
end

#mentionsObject



49
50
51
# File 'lib/mentionable.rb', line 49

def mentions
  extract_mentions(mentionable)
end

#mentions?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/mentionable.rb', line 53

def mentions?
  mentions.present?
end

#mentions_wereObject



57
58
59
# File 'lib/mentionable.rb', line 57

def mentions_were
  extract_mentions(mentionable_before_last_save || '')
end

#new_mentionsObject



61
62
63
# File 'lib/mentionable.rb', line 61

def new_mentions
  mentions - mentions_were
end

#new_mentions?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/mentionable.rb', line 65

def new_mentions?
  new_mentions.present?
end