Class: SlackRubyBotServer::Events::AppMentions::Mention
- Inherits:
-
Object
- Object
- SlackRubyBotServer::Events::AppMentions::Mention
- Includes:
- Loggable
- Defined in:
- lib/slack-ruby-bot-server-events-app-mentions/mentions/mention.rb
Class Attribute Summary collapse
-
.handlers ⇒ Object
Returns the value of attribute handlers.
Class Method Summary collapse
- .inherited(subclass) ⇒ Object
- .invoke(data) ⇒ Object
- .match(match, &block) ⇒ Object
- .mention(*values, &block) ⇒ Object
- .routes ⇒ Object
Class Attribute Details
.handlers ⇒ Object
Returns the value of attribute handlers.
12 13 14 |
# File 'lib/slack-ruby-bot-server-events-app-mentions/mentions/mention.rb', line 12 def handlers @handlers end |
Class Method Details
.inherited(subclass) ⇒ Object
14 15 16 17 |
# File 'lib/slack-ruby-bot-server-events-app-mentions/mentions/mention.rb', line 14 def inherited(subclass) SlackRubyBotServer::Events::AppMentions::Mention.handlers ||= [] SlackRubyBotServer::Events::AppMentions::Mention.handlers << subclass end |
.invoke(data) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/slack-ruby-bot-server-events-app-mentions/mentions/mention.rb', line 24 def invoke(data) finalize_routes! routes.each_pair do |route, | match = route.match(data.text) next unless match call_mention(data.merge(match: Support::Match.new(match)), [:block]) return true end false end |
.match(match, &block) ⇒ Object
37 38 39 |
# File 'lib/slack-ruby-bot-server-events-app-mentions/mentions/mention.rb', line 37 def match(match, &block) routes[match] = { block: block } end |
.mention(*values, &block) ⇒ Object
19 20 21 22 |
# File 'lib/slack-ruby-bot-server-events-app-mentions/mentions/mention.rb', line 19 def mention(*values, &block) values = values.map { |value| value.is_a?(Regexp) ? value.source : Regexp.escape(value) }.join('|') match Regexp.new("(?<mention>#{values})([[:space:]]+(?<expression>.*)|)$", Regexp::IGNORECASE | Regexp::MULTILINE), &block end |
.routes ⇒ Object
41 42 43 |
# File 'lib/slack-ruby-bot-server-events-app-mentions/mentions/mention.rb', line 41 def routes @routes ||= ActiveSupport::OrderedHash.new end |