Class: SlackbotFrd::UserChannelCallbacks
- Inherits:
-
Object
- Object
- SlackbotFrd::UserChannelCallbacks
- Defined in:
- lib/slackbot_frd/lib/user_channel_callbacks.rb
Instance Method Summary collapse
- #add(user:, channel:, callback:) ⇒ Object
- #init(user:, channel:) ⇒ Object
-
#initialize ⇒ UserChannelCallbacks
constructor
A new instance of UserChannelCallbacks.
- #to_s ⇒ Object
- #where(user:, channel:) ⇒ Object
- #where_all ⇒ Object
- #where_include_all(user:, channel:) ⇒ Object
Constructor Details
#initialize ⇒ UserChannelCallbacks
Returns a new instance of UserChannelCallbacks.
5 6 7 8 9 |
# File 'lib/slackbot_frd/lib/user_channel_callbacks.rb', line 5 def initialize @conditions = {} @conditions[:any] = {} @conditions[:any][:any] = [] end |
Instance Method Details
#add(user:, channel:, callback:) ⇒ Object
26 27 28 29 |
# 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:) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# 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 ⇒ Object
49 50 51 |
# File 'lib/slackbot_frd/lib/user_channel_callbacks.rb', line 49 def to_s "#{@conditions}" end |
#where(user:, channel:) ⇒ Object
31 32 33 34 |
# 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 ⇒ Object
36 37 38 |
# File 'lib/slackbot_frd/lib/user_channel_callbacks.rb', line 36 def where_all @conditions[:any][:any] || [] end |
#where_include_all(user:, channel:) ⇒ Object
40 41 42 43 44 45 46 47 |
# 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 |