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

Inherits:
Object
  • Object
show all
Defined in:
/home/apoc/projects/ruby/rbot/lib/rbot/botuser.rb

Overview

This class describes a permission set

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (PermissionSet) initialize

Create a new (empty) PermissionSet



150
151
152
# File '/home/apoc/projects/ruby/rbot/lib/rbot/botuser.rb', line 150

def initialize
  @perm = {}
end

Instance Attribute Details

- (Object) perm (readonly)

Returns the value of attribute perm



147
148
149
# File '/home/apoc/projects/ruby/rbot/lib/rbot/botuser.rb', line 147

def perm
  @perm
end

Instance Method Details

- (Object) inspect

Inspection simply inspects the internal hash



155
156
157
# File '/home/apoc/projects/ruby/rbot/lib/rbot/botuser.rb', line 155

def inspect
  @perm.inspect
end

- (Boolean) permit?(str)

Tells if command cmd is permitted. We do this by returning the value of the deepest Command#path that matches.

Returns:

  • (Boolean)


182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File '/home/apoc/projects/ruby/rbot/lib/rbot/botuser.rb', line 182

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

- (Object) reset_permission(cmd)

Resets the permission for command cmd



175
176
177
# File '/home/apoc/projects/ruby/rbot/lib/rbot/botuser.rb', line 175

def reset_permission(cmd)
  set_permission(cmd, nil)
end

- (Object) set_permission(str, val)

Sets the permission for command cmd to val,



161
162
163
164
165
166
167
168
169
170
171
# File '/home/apoc/projects/ruby/rbot/lib/rbot/botuser.rb', line 161

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