Class: Irc::Bot::Auth::PermissionSet
Overview
This class describes a permission set
Instance Attribute Summary collapse
-
#perm ⇒ Object
readonly
Returns the value of attribute perm.
Instance Method Summary collapse
-
#initialize ⇒ PermissionSet
constructor
Create a new (empty) PermissionSet.
-
#inspect ⇒ Object
Inspection simply inspects the internal hash.
-
#permit?(str) ⇒ Boolean
Tells if command cmd is permitted.
-
#reset_permission(cmd) ⇒ Object
Resets the permission for command cmd.
-
#set_permission(str, val) ⇒ Object
Sets the permission for command cmd to val,.
Constructor Details
#initialize ⇒ PermissionSet
Create a new (empty) PermissionSet
149 150 151 |
# File 'lib/rbot/botuser.rb', line 149 def initialize @perm = {} end |
Instance Attribute Details
#perm ⇒ Object (readonly)
Returns the value of attribute perm.
146 147 148 |
# File 'lib/rbot/botuser.rb', line 146 def perm @perm end |
Instance Method Details
#inspect ⇒ Object
Inspection simply inspects the internal hash
154 155 156 |
# File 'lib/rbot/botuser.rb', line 154 def inspect @perm.inspect end |
#permit?(str) ⇒ Boolean
Tells if command cmd is permitted. We do this by returning the value of the deepest Command#path that matches.
181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# 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) ⇒ Object
Resets the permission for command cmd
174 175 176 |
# File 'lib/rbot/botuser.rb', line 174 def (cmd) (cmd, nil) end |
#set_permission(str, val) ⇒ Object
Sets the permission for command cmd to val,
160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/rbot/botuser.rb', line 160 def (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 |