Class: SlackRubyBotAuthorization::NullRole
- Inherits:
-
Object
- Object
- SlackRubyBotAuthorization::NullRole
- 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
Instance Attribute Summary collapse
-
#denial_handler ⇒ Object
readonly
Returns the value of attribute denial_handler.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #add_commands(*_commands) ⇒ Object
- #add_denial_handler(aproc) ⇒ Object
- #add_users(*_users) ⇒ Object
- #command?(_command) ⇒ Boolean
- #commands ⇒ Object
- #enable_slack_builtin_commands(*commands) ⇒ Object
-
#initialize(_name, &_blk) ⇒ NullRole
constructor
A new instance of NullRole.
- #remove_commands(*_commands) ⇒ Object
- #remove_denial_handler ⇒ Object
- #remove_users(*_users) ⇒ Object
- #user?(_user) ⇒ Boolean
- #users ⇒ Object
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_handler ⇒ Object (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 |
#name ⇒ Object (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
58 59 60 |
# File 'lib/slack_ruby_bot_authorization/role.rb', line 58 def command?(_command) false end |
#commands ⇒ Object
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 = "Unknown command '#{command}'; \ must be one of #{BUILTIN_COMMANDS.inspect}" raise(UnknownBuiltinCommandException, ) 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_handler ⇒ Object
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
54 55 56 |
# File 'lib/slack_ruby_bot_authorization/role.rb', line 54 def user?(_user) false end |
#users ⇒ Object
62 63 64 |
# File 'lib/slack_ruby_bot_authorization/role.rb', line 62 def users [] end |