Class: SlackRubyBotAuthorization::NullRole

Inherits:
Object
  • Object
show all
Defined in:
lib/slack_ruby_bot_authorization/role.rb

Overview

Implement the Null Pattern for the Role class. Other code will search for a matching Role instance. When not found, we want to return an instance of NullRole so that all method calls succeed (unless someone passes a proc with the wrong arity) and we can avoid checking for nil elsewhere.

Direct Known Subclasses

Role

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_name, &_blk) ⇒ NullRole

Returns a new instance of NullRole.



12
13
14
# File 'lib/slack_ruby_bot_authorization/role.rb', line 12

def initialize(_name, &_blk)
  @name = :default
end

Instance Attribute Details

#denial_handlerObject (readonly)

Returns the value of attribute denial_handler.



10
11
12
# File 'lib/slack_ruby_bot_authorization/role.rb', line 10

def denial_handler
  @denial_handler
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/slack_ruby_bot_authorization/role.rb', line 10

def name
  @name
end

Instance Method Details

#add_commands(*_commands) ⇒ Object



20
21
22
# File 'lib/slack_ruby_bot_authorization/role.rb', line 20

def add_commands(*_commands)
  nil
end

#add_denial_handler(aproc) ⇒ Object



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

def add_denial_handler(aproc)
  return if aproc.arity == 3
  raise(DenialProcArityException, 'Must accept 3 arguments')
end

#add_users(*_users) ⇒ Object



16
17
18
# File 'lib/slack_ruby_bot_authorization/role.rb', line 16

def add_users(*_users)
  nil
end

#command?(_command) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/slack_ruby_bot_authorization/role.rb', line 58

def command?(_command)
  false
end

#commandsObject



66
67
68
# File 'lib/slack_ruby_bot_authorization/role.rb', line 66

def commands
  []
end

#enable_slack_builtin_commands(*commands) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/slack_ruby_bot_authorization/role.rb', line 29

def enable_slack_builtin_commands(*commands)
  missing = commands.none? do |command|
    BUILTIN_COMMANDS.include?(command.downcase)
  end

  return unless missing

  message = "Unknown command '#{command}'; \
  must be one of #{BUILTIN_COMMANDS.inspect}"

  raise(UnknownBuiltinCommandException, message)
end

#remove_commands(*_commands) ⇒ Object



46
47
48
# File 'lib/slack_ruby_bot_authorization/role.rb', line 46

def remove_commands(*_commands)
  nil
end

#remove_denial_handlerObject



50
51
52
# File 'lib/slack_ruby_bot_authorization/role.rb', line 50

def remove_denial_handler
  nil
end

#remove_users(*_users) ⇒ Object



42
43
44
# File 'lib/slack_ruby_bot_authorization/role.rb', line 42

def remove_users(*_users)
  nil
end

#user?(_user) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/slack_ruby_bot_authorization/role.rb', line 54

def user?(_user)
  false
end

#usersObject



62
63
64
# File 'lib/slack_ruby_bot_authorization/role.rb', line 62

def users
  []
end