Class | Irc::Bot::Auth::PermissionSet |
In: |
lib/rbot/botuser.rb
|
Parent: | Object |
This class describes a permission set
perm | [R] |
Create a new (empty) PermissionSet
# File lib/rbot/botuser.rb, line 149 149: def initialize 150: @perm = {} 151: end
Inspection simply inspects the internal hash
# File lib/rbot/botuser.rb, line 154 154: def inspect 155: @perm.inspect 156: end
Tells if command cmd is permitted. We do this by returning the value of the deepest Command#path that matches.
# File lib/rbot/botuser.rb, line 181 181: def permit?(str) 182: cmd = str.to_irc_auth_command 183: # TODO user-configurable list of always-allowed commands, 184: # for admins that want to set permissions -* for everybody 185: return true if cmd.command == :login 186: allow = nil 187: cmd.path.reverse.each { |k| 188: if @perm.has_key?(k) 189: allow = @perm[k] 190: break 191: end 192: } 193: return allow 194: end
Resets the permission for command cmd
# File lib/rbot/botuser.rb, line 174 174: def reset_permission(cmd) 175: set_permission(cmd, nil) 176: end
Sets the permission for command cmd to val,
# File lib/rbot/botuser.rb, line 160 160: def set_permission(str, val) 161: cmd = str.to_irc_auth_command 162: case val 163: when true, false 164: @perm[cmd.command] = val 165: when nil 166: @perm.delete(cmd.command) 167: else 168: raise TypeError, "#{val.inspect} must be true or false" unless [true,false].include?(val) 169: end 170: end