class SlackbotFrd::UserChannelCallbacks
Public Class Methods
new()
click to toggle source
# File lib/slackbot_frd/lib/user_channel_callbacks.rb, line 5 def initialize @conditions = {} @conditions[:any] = {} @conditions[:any][:any] = [] end
Public Instance Methods
add(user:, channel:, callback:)
click to toggle source
# File lib/slackbot_frd/lib/user_channel_callbacks.rb, line 26 def add(user:, channel:, callback:) init(user: user, channel: channel) @conditions[user][channel].push(callback) end
init(user:, channel:)
click to toggle source
# File lib/slackbot_frd/lib/user_channel_callbacks.rb, line 11 def init(user:, channel:) unless user Log::error("#{self.class}: Invalid user '#{user}'") raise InvalidUserError.new end unless channel Log::error("#{self.class}: Invalid channel '#{channel}'") raise InvalidChannelError.new end @conditions[user] ||= {} @conditions[user][:any] ||= [] @conditions[:any][channel] ||= [] @conditions[user][channel] ||= [] end
to_s()
click to toggle source
# File lib/slackbot_frd/lib/user_channel_callbacks.rb, line 49 def to_s "#{@conditions}" end
where(user:, channel:)
click to toggle source
# File lib/slackbot_frd/lib/user_channel_callbacks.rb, line 31 def where(user:, channel:) init(user: user, channel: channel) @conditions[user][channel] || [] end
where_all()
click to toggle source
# File lib/slackbot_frd/lib/user_channel_callbacks.rb, line 36 def where_all @conditions[:any][:any] || [] end
where_include_all(user:, channel:)
click to toggle source
# File lib/slackbot_frd/lib/user_channel_callbacks.rb, line 40 def where_include_all(user:, channel:) init(user: user, channel: channel) retval = @conditions[:any][:any].dup || [] retval.concat(@conditions[user][:any] || []) retval.concat(@conditions[:any][channel] || []) retval.concat(@conditions[user][channel] || []) retval end