Allow hooks for specific matcher groups #144

Merged
merged 2 commits into from Oct 5, 2013

2 participants

@programble

Fixes #143.

Hooks without groups are always executed. Matchers execute the global hooks (the ones lacking groups) along with the hooks in their group.

@dominikh dominikh commented on an outdated diff Oct 4, 2013
lib/cinch/plugin.rb
@@ -282,14 +283,20 @@ def __hooks(type = nil, events = nil)
if hooks.is_a?(Hash)
hooks = hooks.map { |k, v| v }
end
- return hooks.select { |hook| (events & hook.for).size > 0 }
+ hooks.select! { |hook| (events & hook.for).size > 0 }
+ end
+
+ if group.nil?
+ return hooks.select { |hook| hook.group.nil? }
+ else
+ return hooks.select { |hook| hook.group.nil? || hook.group == group }
@dominikh
Cinch IRC Framework member
dominikh added a line comment Oct 4, 2013

This whole if/else can be unconditionally reduced to the body of the else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@dominikh
Cinch IRC Framework member

Looks good to me, apart from the style comment. Will test and then merge.

@dominikh dominikh merged commit c937c1a into cinchrb:master Oct 5, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment