class Irc::Bot::Auth::PermissionSet
This class describes a permission set
Attributes
perm[R]
Public Class Methods
new()
click to toggle source
Create a new (empty) PermissionSet
# File lib/rbot/botuser.rb, line 149 def initialize @perm = {} end
Public Instance Methods
inspect()
click to toggle source
Inspection simply inspects the internal hash
# File lib/rbot/botuser.rb, line 154 def inspect @perm.inspect end
permit?(str)
click to toggle source
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 def permit?(str) cmd = str.to_irc_auth_command # TODO user-configurable list of always-allowed commands, # for admins that want to set permissions -* for everybody return true if cmd.command == :login allow = nil cmd.path.reverse.each { |k| if @perm.has_key?(k) allow = @perm[k] break end } return allow end
reset_permission(cmd)
click to toggle source
Resets the permission for command cmd
# File lib/rbot/botuser.rb, line 174 def reset_permission(cmd) set_permission(cmd, nil) end
set_permission(str, val)
click to toggle source
Sets the permission for command cmd to val,
# File lib/rbot/botuser.rb, line 160 def set_permission(str, val) cmd = str.to_irc_auth_command case val when true, false @perm[cmd.command] = val when nil @perm.delete(cmd.command) else raise TypeError, "#{val.inspect} must be true or false" unless [true,false].include?(val) end end