Class: TelegramBotEngine::Authorizer

Inherits:
Object
  • Object
show all
Defined in:
lib/telegram_bot_engine/authorizer.rb

Class Method Summary collapse

Class Method Details

.authorized?(username) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
8
9
10
# File 'lib/telegram_bot_engine/authorizer.rb', line 5

def self.authorized?(username)
  return true if TelegramBotEngine.config.allowed_usernames.nil?

  allowed = resolve_allowed_usernames
  allowed.map(&:downcase).include?(username&.downcase)
end

.resolve_allowed_usernamesObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/telegram_bot_engine/authorizer.rb', line 14

def self.resolve_allowed_usernames
  config = TelegramBotEngine.config.allowed_usernames

  case config
  when Array
    config
  when Proc
    config.call
  when :database
    TelegramBotEngine::AllowedUser.pluck(:username)
  else
    []
  end
end