Skip to content

Commit

Permalink
WIP: Add matched attachment info to the match param
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Dudzinski committed Feb 28, 2018
1 parent d172675 commit 56d8771
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
6 changes: 3 additions & 3 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2018-02-28 18:47:19 +0100 using RuboCop version 0.51.0.
# on 2018-02-28 20:15:32 +0100 using RuboCop version 0.51.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand Down Expand Up @@ -37,7 +37,7 @@ Metrics/BlockLength:
# Offense count: 1
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 132
Max: 139

# Offense count: 2
Metrics/CyclomaticComplexity:
Expand All @@ -49,7 +49,7 @@ Metrics/CyclomaticComplexity:
Metrics/LineLength:
Max: 147

# Offense count: 11
# Offense count: 12
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 23
Expand Down
10 changes: 9 additions & 1 deletion lib/slack-ruby-bot/commands/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,15 @@ def match_attachments(data, route)
fields_to_scan.each do |field|
next unless attachment[field]
match = route.match(attachment[field])
return match if match
next unless match
# add access to the matched attachment
match.singleton_class.send(
:define_method, :attachment, -> { attachment }
)
match.singleton_class.send(
:define_method, :attachment_field, -> { field }
)
return match
end
end
false
Expand Down
6 changes: 3 additions & 3 deletions spec/slack-ruby-bot/commands/attachment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
Class.new(SlackRubyBot::Commands::Base) do
attachment(/New comment matched by pretext #(?<id>\d+)/) do |client, data, match|
client.say(text: "The id: #{match[:id]}", channel: data.channel)
client.say(text: "Comment: '#{data.attachments[0].text}'", channel: data.channel)
client.say(text: "Comment: '#{match.attachment.text}'", channel: data.channel)
end
attachment(/New comment matched by text #(?<id>\d+)/) do |client, data, match|
client.say(text: "The id: #{match[:id]}", channel: data.channel)
client.say(text: "Comment: '#{data.attachments[0].title}'", channel: data.channel)
client.say(text: "Comment: '#{match.attachment.title}'", channel: data.channel)
end
attachment(/New comment matched by title #(?<id>\d+)/) do |client, data, match|
client.say(text: "The id: #{match[:id]}", channel: data.channel)
client.say(text: "Comment: '#{data.attachments[0].pretext}'", channel: data.channel)
client.say(text: "Comment: '#{match.attachment.pretext}'", channel: data.channel)
end
end
end
Expand Down

0 comments on commit 56d8771

Please sign in to comment.