Class: Irc::Bot::Auth::PermissionSet

Inherits:
Object
  • Object
show all
Defined in:
lib/rbot/botuser.rb

Overview

This class describes a permission set

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePermissionSet

Create a new (empty) PermissionSet



149
150
151
# File 'lib/rbot/botuser.rb', line 149

def initialize
  @perm = {}
end

Instance Attribute Details

#permObject (readonly)

Returns the value of attribute perm.



146
147
148
# File 'lib/rbot/botuser.rb', line 146

def perm
  @perm
end

Instance Method Details

#inspectObject

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.

Returns:

  • (Boolean)


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 reset_permission(cmd)
  set_permission(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 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