Module: SlackRubyBotAuthorization::Utils

Included in:
Authorization, Command, CommandAudit, Commands, Role, Roles
Defined in:
lib/slack_ruby_bot_authorization/utils.rb

Overview

Methods that don’t fit in any other class and also may be needed by multiple classes/modules.

Constant Summary collapse

EmptyDenialProc =

Used as the default denial handler for Command instances. When the proc returns true, it allows the global default handler to also run. We want the empty handler to return true so that the default (if it exists) will run.

proc do |_client, _data, _match|
  true
end

Instance Method Summary collapse

Instance Method Details

#extract_command(match) ⇒ Object



33
34
35
36
# File 'lib/slack_ruby_bot_authorization/utils.rb', line 33

def extract_command(match)
  return unless match.is_a?(MatchData) && match.names.include?('command')
  match[:command].downcase
end

#extract_details(data, match) ⇒ Object

Authorization only works when we’ve been passed a data object with a user field and a match object that contains a command field.

Extract those items and return them in an array. If those items don’t exist in the form we expect, return nil in place of those objects.



25
26
27
# File 'lib/slack_ruby_bot_authorization/utils.rb', line 25

def extract_details(data, match)
  [extract_user(data), extract_command(match)]
end

#extract_user(data) ⇒ Object



29
30
31
# File 'lib/slack_ruby_bot_authorization/utils.rb', line 29

def extract_user(data)
  data.respond_to?(:user) ? data.user : nil
end

#normalize_string(obj) ⇒ Object

Takes a String or Symbol, manipulates it, and returns a Symbol.



14
15
16
# File 'lib/slack_ruby_bot_authorization/utils.rb', line 14

def normalize_string(obj)
  obj.to_s.downcase.to_sym
end